Difference between .bashrc and .bash_profile
What's the difference between
.bash_profile, and when do you configure which?
I.e if I configure the
.bash_profile, do I still need to configure
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
bash is your default shell, the differences are described in the
bash man page (
When bash is invoked as an interactive login shell, or as a non-interac- tive 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.
There is more detail in the man page that covers POSIX-shell compatibility mode, which is where
.profile comes from. Read the whole man page section for all the details.
If you configure
.bash_profile, you won't also need to configure
I like to keep my own aliases and commands in
.profile so that if I mess up anything, I know that I can always delete the
.profile without affecting the system at large or other applications that modify
.bash_profile (like MacPorts).
To use a
.profile, you may need to include the line
source ~/.profile in your
.bash_profile so that the
.profile file is read (see Ned Deily's answer).
.profile is executed by bash when you get a normal shell process -- e.g. you open a terminal tool. .bash_profile is executed by bash for login shells -- so this is when you telnet/ssh into your machine remotely for instance. For instance if you ssh remotely into a machine (let's say you open an X Terminal) you will get initially .bash_profile executed. If in that XTerminal you type "xterm" and spawn another X Terminal, then .profile will be executed for the second instance of XTerminal. The files reside in your home directory (~). If I'm not mistaking by default they both execute ~/.bashrc so you can edit that to configure common settings/variables for both login and non login shells (e.g setting PATH, some aliases/shortcuts etc). You might want occasionally to configure certain things differently for these 2 but I have never encountered that need -- however, the possibility is there.
for the fast and simple config (where you don't want complicate things) simply configure everything in your ~/.profile. Only when you run into some troubles (but probably will never) learn more about the .bash_login or .bash_profile ;)
I'm on OS X too, and never needed .bash_profile or .bash_login and using only .profile, but your mileage may vary...