Linux下与环境变量有关的配置文件

来源:互联网 发布:云计算使用举例 编辑:程序博客网 时间:2024/04/30 00:55
1、
CentOS:
/etc/profile, /etc/bashrc
~/.bashrc, ~/.bash_profile, ~/.bash_logout, ~/bash_history

Ubuntu:
/etc/profile, /etc/bash.bashrc
~/.bashrc, ~/.profile, ~/.bash_logout, ~/bash_history


2、说明(不一定正确)
①CentOS的~/.bash_profile相当于Ubuntu的~/.profile,而且它们都会调用~/.bashrc
②login shell读取配置文件的顺序:/etc/profile ----> ~/.bash_profile(~/.profile)(此外,还调用~/.bashrc)
③non-login shell读取配置文件的顺序(CentOS):/etc/bashrc ----> ~/.bashrc
【参考资料】[Bash: about .bashrc, .bash_profile, .profile, /etc/profile, etc/bash.bashrc and others](http://stefaanlippens.net/bashrc_and_others)


3、关于修改PATH
修改/etc/profile、~/.bashrc、~/.bash_profile都可行(如果想在所有用户的shell下都生效,就编辑/etc/profile文件)


4、. 或 source 命令
. <config_file>
or:
source <config_file>
说明:
(1) 仅对当前shell有效,如果想对所有shell生效,就注销当前用户;如果想永久生效,就重启系统。
(2) 如果修改配置文件使删除某些环境变量,则执行 . 或 source 命令之后这些环境变量依然有效。