Hack 84. Execution Sequence of .bash_* files
by Ramesh
What is the sequence in which the following files are executed?
- /etc/profile
- ~/.bash_profile
- ~/.bashrc
- ~/.bash_login
- ~/.profile
- ~/.bash_logout
Execution sequence for interactive login shell
Following pseudo code explains the sequence of execution of these files.
- execute /etc/profile
- IF ~/.bash_profile exists THEN
- execute ~/.bash_profile
- ELSE
- IF ~/.bash_login exist THEN
- execute ~/.bash_login
- ELSE
- IF ~/.profile exist THEN
- execute ~/.profile
- END IF
- END IF
- END IF
When you logout of the interactive shell, following is the sequence of execution:
- IF ~/.bash_logout exists THEN
- execute ~/.bash_logout
- END IF
Please note that /etc/bashrc is executed by ~/.bashrc as shown below:
- # cat ~/.bashrc
- if [ -f /etc/bashrc ]; then
- . /etc/bashrc
- Fi
Execution sequence for interactive non-login shell
While launching a non-login interactive shell, following is the sequence of execution:
- IF ~/.bashrc exists THEN
- execute ~/.bashrc
- END IF
Note: When a non-interactive shell starts up, it looks for ENV environment variable, and executes the file-name value mentioned in the ENV variable.
当前内容版权归 Ramesh Natarajan 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Ramesh Natarajan .