您的位置:首页 > 运维架构 > Shell

linux下.bash_*文件的执行顺序

2013-10-10 15:30 218 查看
摘自:Linux 101 Hacks: 84

下列文件的执行顺序是什么?

/etc/profile
~/.bash_profile
~/.bashrc
~/.bash_login
~/.profile
~/.bash_logout


交互式登录 shell 的执行顺序

下面的伪代码将说明这些文件的执行顺序 

execute /etc/profile
IF ~/.bash_profile exists THEN
execute ~/.bash_profile
ELSE
IF ~/.bash_login exist THEN
execute ~/.bash_login
ELSE
IF ~/.profile exist THEN
execute ~/.profile
END IF
END IF
END IF


当你从交互式 shell 中注销,以下是执行顺序:

IF ~/.bash_logout exists THEN
execute ~/.bash_logout
END IF


请注意 /etc/bashrc 是通过~/.bashrc 执行,如下所示:

# cat ~/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
Fi


非登录交互式 shell 的 执行顺序 

当你启动一个非登录交互式 shell,下面是执行顺序

IF ~/.bashrc exists THEN
execute ~/.bashrc
END IF


[注意:当一个非交互式 shell 启动,它会寻找环境变量 ENV,并执行环境变量 ENV 里的文件名变量。] 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐