Home > Geeky, Mac OS X > Using .bashrc with Terminal

Using .bashrc with Terminal

I got a question from a user today that was pretty interesting. Boiled down, it was “I’ve set up a .bashrc file with my preferred settings. It works fine in XWindows with xterm, but is being ignored by Terminal. Why?”

This has to do with how the bash shell handles different shells. If you read the bash man page (‘man bash’), in the section on startup files, it explains which files are read when. The tricky part is that there are two types of shells: “login” shells and “non-login” shells, and bash reads different files depending on the type of shell.

A “login” shell reads ~/.profile but not ~/.bashrc
A “non-login” shell reads ~/.bashrc but not ~/.profile

A new Terminal window in OS X starts a “login” shell and hence reads ~/.profile but not ~/.bashrc
The situation is reversed for xterm (running under X11 in OS X).

What should fix it is to set up a .profile file to that sources your .bashrc file like this:

if [ -f ~/.bashrc ]; then
. ~/.bashrc

That way, you don’t have to worry about making changes to .profile; Terminal will just get the changes from .bashrc. For what it’s worth, this is an issue with several Unix-based OSs.

Categories: Geeky, Mac OS X
  1. November 9, 2011 at 5:54 pm

    Its works.

    I am using that way;
    $ echo “source ~/.bashrc” >> .bash_profile

  2. imme5150
    September 23, 2012 at 10:53 pm

    For me on OSX 10.5 it’s .bash_profile, not .profile

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: