notes blog about

Bash Startup Files

When bash is started it runs a series of scripts to prepare the environment for user. These scripts, for example, set the environment variables, create command aliases, run programs.

There are two main types of a shell instance, interactive and noninteractive. However, noninteractive shells (such as those running shell scripts) usually don’t read any startup files. To run a noninteractive shell as a login shell, to force it to run startup files, start the shell with the -l or --login option.

Interactive shell can be a:

… to find out run echo $0 | perl -lne 'print /^\-/ ? "" : "non-", "login shell"'

Login shell Non-login shell
Global config /etc/profile (, /etc/profile.d/) /etc/bash.bashrc, /etc/bash/bashrc, /etc/bashrc
User config ~/.bash_profile, ~/.bash_login, ~/.profile (only the first found is run) ~/.bashrc

Creating a symlink between ~/.bashrc and ~/.bash_profile will ensure that the same startup scripts run for both login and non-login sessions. Debian’s ~/.profile sources ~/.bashrc, which has the same effect.