Knowing the order of execution of the environment variables for different OS Shell(s) is very important for a system administrator. This might be useful for setting up cron jobs or for understanding differences in commands run in an interactive shell vs batch jobs using a non-interactive shell.
1. Shell: CSH
Startup (order):
--> .cshrc (always) --> .login (login shells)
Termination:
--> .logout (login shells)
Others:
.history (saves history based on "$savehist")
2. Shell: tcsh
Startup (order):
--> /etc/csh.cshrc (always) --> /etc/csh.login (login shells) --> .tcshrc (always) --> .cshrc (if no .tcshrc file is present) --> .login (login shells)
Termination:
-->.logout (login shells)
Others:
--> .history (saves history based on "$savehist") --> .cshdirs (saves directory stack)
3. Shell: sh
Startup (order):
--> /etc/profile (login shells)
Termination:
Any command or script specified using the command: trap "command" 0
Others:
--> .profile (login shells)
4. Shell: ksh
Startup (order):
--> /etc/profile (login shells) --> .profile (login shells) --> $ENV (always, if it is set)
Termination:
Any command or script specified using the command: trap "command" 0
5. Shell: bash
Startup (order):
--> /etc/profile (login shells) --> .bash_profile (login shells) --> .profile (login if no .bash_profile file is present) --> .bashrc (interactive non-login shells) --> $ENV (non-interactive shells)
Termination:
--> .bash_logout (login shells)
Others:
--> .inputrc (readline initialization)
6. Shell: zsh
Startup (order):
--> .zshenv (always, unless the -f option is specified) --> .zprofile (login shells) --> .zshrc (interactive shells, unless the -f option is specified) --> .zlogin (login shells)
Termination:
--> .zlogout (login shells)