linux下环境变量

/etc/profile 系统级别,为每个用户设置环境变量,在用户第一次登录系统的时候就会执行,并且会执行/etc/profile.d/下的配置文件

/etc/bashrc 系统级别 运行bash shell时被读取,即每次切换shell就会有

~/.bash_profile 用户级别,登录时

~/.bashrc 用户级别

用户登录后加载profile和bashrc的流程如下:
1)/etc/profile-------->/etc/profile.d/*.sh
2)$HOME/.bash_profile-------->$HOME/.bashrc---------->/etc/bashrc
说明:
bash首先执行/etc/profile脚本,/etc/profile脚本先依次执行/etc/profile.d/*.sh
随后bash会执行用户主目录下的.bash_profile脚本,.bash_profile脚本会执行用户主目录下的.bashrc脚本, 而.bashrc脚本会执行/etc/bashrc脚本 至此,所有的环境变量和初始化设定都已经加载完成.