Wednesday, April 8, 2020

BASH startup file loading order

The loading order of Bash startup files is first dependent on the type of shell that Bash think it is in.
login shell is when the user logs in from tty (not through a GUI) or logs in remotely (e.g. through ssh).
non-login shell is started in other ways such as gnome-terminal which is started by Gnome (it is a login shell that launched Gnome).
Note: The exception is OSX's Terminal.app which is treated as a login shell.
For non-login shells (e.g. gnome-terminal) the order is:

   /etc/bash.bashrc
   ~/.bashrc
For login-shells (including Terminal.app) the order is: /etc/profile and then first of:

   /etc/profile
Followed by the first of the following:

     ~/.bash_profile
     ~/.bash_login
     ~/.profile