Thursday, November 14, 2013

What's the difference between .bashrc and .bash_profile?

A very precise & concise post about this is here: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

A short answer is,

.bash_profile is executed to configure your shell when you login (type username and password) via console, locally or remotely. Just like each time when you ssh to your cluster/server, it will automatically call .bash_profile.

.bashrc is executed when you start a new bash instance, either by opening a new terminal window or start a new bash script. So, say in Mac, when you type Command+T to open a new tab, it will call .bashrc. 

Note that Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calls .bash_profile instead of .bashrc. This is an exception!

Josh recommend to solve the confusion by calling .bashrc in .bash_profile, such as 
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

No comments:

Post a Comment