Bash is a Bourne-like shell. It reads commands from ~/.bash_profile
when it is invoked as the login shell, and if that file doesn't existexist¹, it tries reading ~/.profile
instead.
~/.profile
is the place to put stuff that applies to your whole session, such as programs that you want to start when you log in (but not graphical programs, they go into a different file), and environment variable definitions.~/.bashrc
is the place to put stuff that applies only to bash itself, such as alias and function definitions, shell options, and prompt settings. (You could also put key bindings there, but for bash they normally go into~/.inputrc
.)~/.bash_profile
can be used instead of~/.profile
, but it is read by bash only, not by any other shell. (This is mostly a concern if you also needwant your initialization files to work on multiple machines and your login shell isn't bash on all of them.) This is a logical place to include~/.bashrc
if the shell is interactive. I recommend the following contents in~/.bash_profile
:if [ -r ~/.profile ]; then . ~/.profile; fi case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
Note that you may see here and there recommendations to either put environment variable definitions in ~/.bashrc
or always launch login shells in terminals. Both are bad ideas. The most common problem with either of these ideas is that your environment variables will only be set in programs launched via the terminal, not in programs started directly with an icon or menu or keyboard shortcut.
¹ For completeness, by request: if .bash_profile
doesn't exist, bash also tries .bash_login
before falling back to .profile
. Feel free to forget it exists.