Before explaining the Bourne Again SHell (BASH) 3 default startup files order, here are some needed definitions:
- Login shell: its first character of argument zero is a – or it’s started with the -l option.
- Interactive shell: it’s started without non-option arguments and without the -c option and its standard input and error are both connected to terminals. It can be started with the -i option.
Now that we know the differences between them, let’s explain the default startup process for each kind of shell in BASH 3:
- Login shell:
- It reads and executes /etc/profile (if it exists)
- It reads one (and only one) of the following files and executes it. The order of checking is:
- ~/.bash_profile
- ~/.bash_login
- ~/.profile
- Interactive shell:
- It reads and executes /etc/bash.bashrc (if it exists)
- It reads and executes ~/.bashrc (if it exists)
Additionally, login shells reads and executes ~/.bash_logout (if it exists) on exit.