login方式登录
login登录方式有:ssh等。
读取顺序为:
/etc/profile -> (~/.bash_profile, ~/.bash_login, ~/.profile)
non-login方式登录
non-login登录方式有:screen命令,bash命令,su切换用户,从图形界面打开teminal等。
读取顺序为:
Ubuntu:/etc/bash.bashrc -> ~/.bashrc
Red Hat:~/.bashrc
Mac(bash):未知 -> (~/.bash_profile, ~/.profile)
Mac(zsh):未知 -> ~/.zshrc
其它
上述的读取顺序都是系统规定,不会被改变的顺序,但很多情况下,一个配置文件里还会读取另一些配置文件。
例如,/etc/profile中会有一段命令会执行/etc/profile.d/*.sh里的脚本。
Ubuntu下的/etc/profile还会去执行/etc/bash.bashrc。
Red Hat下的~/.bash_profile会去执行~/.bashrc,~/.bashrc会去执行/etc/bashrc。
这些都是写在配置文件中,可以看见相应逻辑的。
备注
暂时不讨论~/.bash_logout。
本文详细解析了Linux系统下login与non-login登录方式的区别,以及不同登录方式下shell配置文件的读取顺序。涵盖了ssh、screen、bash命令等多种登录手段,深入探讨Ubuntu、RedHat、Mac等系统的具体配置。
958

被折叠的 条评论
为什么被折叠?



