ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 转 bash bashrc profile 区别

转 bash bashrc profile 区别

原创 Linux操作系统 作者:serapy 时间:2011-06-21 10:46:28 0 删除 编辑
用户登录后加载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脚本

至此,所有的环境变量和初始化设定都已经加载完成.
bash随后调用terminfo和inputrc,完成终端属性和键盘映射的设定.

其中PATH这个变量特殊说明一下:
如果是超级用户登录,在没有执行/etc/profile之前,PATH已经设定了下面的路径:
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
如果是普通用户,PATH在/etc/profile执行之前设定了以下的路径:
/usr/local/bin:/bin:/usr/bin

这里要注意的是:在用户切换并加载变量,例如su -,这时,如果用户自己切换自己,比如root用户再用su - root切换的话,加载的PATH和上面的不一样.
准确的说,是不总是一样.所以,在/etc/profile脚本中,做了如下的配置:
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

如果是超级用户登录,在/etc/profile.d/krb5.sh脚本中,在PATH变量搜索路径的最前面增加/usr/kerberos/sbin:/usr/kerberos/bin
如果是普通用户登录,在/etc/profile.d/krb5.sh脚本中,在PATH变量搜索路径的最前面增加/usr/kerberos/bin

在/etc/profile脚本中,会在PATH变量的最后增加/usr/X11R6/bin目录
在$HOME/.bash_profile中,会在PATH变量的最后增加$HOME/bin目录

以root用户为例,最终的PATH会是这样(没有其它自定义的基础上)
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

以alice用户(普通用户)为例
/usr/kerberos/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/alice/bin

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14766028/viewspace-700362/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-10-26

  • 博文量
    38
  • 访问量
    179299