Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This question already has an answer here:

I found a lot of people figuring out why instruction similar to this :

Put X to your ~/.bashrc and you can do Y

don't work.

It always turns out that Mac OS X's bash's startup files (or Mac's Bash itself) doesn't source ~/.bashrc file (neither when login shell, or shell spawned from window system - like Terminal app in Mac OS X)

I wonder why, if all other Unix like systems with Bash I work before done this.

PS:

I found what Bash itself says about startup files (which could be helpful) :

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

Source : http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

share|improve this question
add comment

marked as duplicate by bmike Mar 14 at 2:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

In OSX the terminal you get is a login session so reads .bash_profile etc.

On other Unices xterm runs a non login shell by default so they read .bashrc

From the GNU document you referred to

Invoked as an interactive non-login shell

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.

So, typically, your ~/.bash_profile contains the line

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

after (or before) any login-specific initializations.

share|improve this answer
    
Unicies = Unixes ? –  bluesm Feb 3 at 13:07
    
Well Unices I meant - I leant Latin at school so remover the plural form - see en.wikipedia.org/wiki/Unix –  Mark Feb 3 at 13:10
add comment

bash only reads .bashrc for non-login shells:

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

As Terminal starts bash as a login shell (run w to see that the bash instances are executed as -bash), .bashrc is never read automatically.

share|improve this answer
    
So the point is, that Termina app on Mac OS X always create "login" instance of bash ? Why ? If you really don't login. (You have login earlier from GUI) –  bluesm Feb 3 at 12:59
    
Why other unix systems DO read ~/.bashrc ? –  bluesm Feb 3 at 13:05
    
Nobody here is in a position to explain design decisions made by Apple. I could easily argue both sides but this doesn't help either. So just accept it as it is is probably the best option –  patrix Feb 3 at 13:06
    
Well it is the first time you run the shell as you so it is a login, in X11 based Unices you start by running the shell which then runs X so it is not a login –  Mark Feb 3 at 13:11
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.