Go to the previous, next section.
When and how Bash executes startup files.
For Login shells (subject to the -noprofile option):
On logging in:
If `/etc/profile' exists, then source it.
If `~/.bash_profile' exists, then source it,
else if `~/.bash_login' exists, then source it,
else if `~/.profile' exists, then source it.
On logging out:
If `~/.bash_logout' exists, source it.
For non-login interactive shells (subject to the -norc and -rcfile options):
On starting up:
If `~/.bashrc' exists, then source it.
For non-interactive shells:
On starting up:
If the environment variable ENV is non-null, expand the
variable and source the file named by the value. If Bash is
not started in Posix mode, it looks for BASH_ENV before
ENV.
So, typically, your ~/.bash_profile contains the line
if [ -f ~/.bashrc ]; then source ~/.bashrc; fi
after (or before) any login specific initializations.
If Bash is invoked as sh, it tries to mimic the behavior of
sh as closely as possible. For a login shell, it attempts to
source only `/etc/profile' and `~/.profile', in that order.
The -noprofile option may still be used to disable this behavior.
A shell invoked as sh does not attempt to source any other
startup files.
When Bash is started in POSIX mode, as with the
-posix command line option, it follows the Posix 1003.2
standard for startup files. In this mode, the ENV
variable is expanded and that file sourced; no other startup files
are read.
Go to the previous, next section.