(Download pdf of this post here)
Knowledge of startup files helps in setting environment variables, among other things. Below is some information on some popular shells.
1 tcsh
- tcsh executes system-wide startup file usually located at /etc/csh.cshrc
- This fi le is not usually editable for everyone.
- tcsh will then executes .tcshrc and if not found executes .cshrc in local home directory.
- If tcsh is executed as login shell, then global con g is executed from /etc/csh.login followed by ~/.login fi le.
2 csh
- csh behaves much the same as tcsh. It executes system-wide startup file usually located at /etc/csh.cshrc, which is editable by priviledged users.
- For login shell, /etc/csh.login fi le is executed in addition to /etc/csh.cshrc {Need to double check if both or only one of .login .cshrc is executed when login shell is invoked.}
- tcsh will then execute ~/.tcshrc and if not found execute ~/.cshrc file.
- If tcsh is executed as login shell, then global con g is executed from /etc/csh.login followed by .login file in personal home directory.
3 bash
3.1 For login shell or with --login option
- Bash looks for system wide settings in /etc/profile le which is not editable to non-root user.
- After reading that le, it looks for ~/.bash_profile, ~/.bash_login and ~/.profile in that order. It executes the fi rst fi le that is found and readable. It does NOT execute all the files.
- Using --noprofile option will inhibit the above lookup.
- When shell is exited, bash executes commands from ~/.bash_logout file.
3.2 Started as interactive non-login shell
- Bash reads and executes commands from ~/.bashrc. This can be overridden by using --norc option.
- The --rcfile will override above behavior and bash will read and execute commands from ~/.bashrc instead.
- There are many other ways to invoke a shell and they can be read in [2]
References
[1] http://www.acm.uiuc.edu/workshops/cool unix/tcsh-startup.html
[2] http://www.gnu.org/software/bash/manual/html node/Bash-Startup-Files.html
Labels: bash, bashrc, csh, cshrc, shell, shell environment variables, shell startup files, tcsh