Linux 系统中更新环境变量PATH可以通过更改不同的文件进行更改,但是在这之前我们需要知道login shell 和 non-login shell
login shell
login shell 取得bash 时需要完整的登录流程,需要读取完整的配置文件,例如我们通过tty1-tty6通过用户名和密码登录的shell就属于login shell,ssh 远程登录的用户的shell也是login shell。
login shell 主要读取两个配置文件/etc/profile
和~/.bash_profile
首先/etc/profile
在系统登录的时候进行配置环境
~/.bash_profile
是login shell 登录时进行读取,且该文件会读取
~/.bash_profile
~/.bash_login
~/.profile
三个文件
实线的方向是主线流程,虚线的方向则是被调用的配置文件
其中/etc/profile.d/*
文件是在login shell登录的时候执行的可执行文件
non-login shell
non-login shell 取得bash的接口不需要重复登录,比如在图形化界面的
ctl+alt+t
出来的shell就属于non-login shell 直接在命令行中通过su username
也属于non-login shell。
su -l username
可以登录login shell