1.login shell,or with –login

作为交互shell启动,并且是个登录shell:

  • 首先读取/etc/profile:
  • 完了后按顺序自动搜索:(找到了就读取,后面的就不会读取了)
    1. ~/.bash_profile
    2. ~/.bash_login
    3. ~/.profile
  • 当login shell退出时,读取并执行~/.bash_logout

2.non-login shell

当输入了用户名+密码后,就会启动一个non-login shell。(也就是sudo su后,然后又切回了某个用户账号)

  • 如果~/.bashrc存在,就会读取并执行

一般来说(也可能没有,所以看具体情况配置),~/.bash_profile(这个是指上面的login shell的读取流程)会包含下面这个语句:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

这样切用户的时候会自动加载他的配置。

总结

##login shell
/etc/profile
~/.bash_profile	//首先找这个,如果没用才找~/.bash_login
	(~/.bashrc) 可能包含
		(/etc/bashrc) 可能包含
~/.bash_login
~/.profile

##non-login shell
~/.bashrc