红联Linux门户
Linux帮助

login no-login shell 的执行顺序

发布时间:2008-08-30 21:43:48来源:红联作者:Version
Login shells

引用:
/etc/profile
/etc/profile.d
~/.bash_profile
~/.bashrc
/etc/bashrc

Non-login shells
~/.bashrc
/etc/bashrc
/etc/profile.d


login nologin shell的执行顺序按照上述顺序执行.

查看/etc/profile

#cat /etc/profile

有以下内容,说明了执行 /etc/profile.d/里的*.sh

引用:
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done


/etc/profile.d里面有以下脚本

引用:
-rwxr-xr-x 1 root root 720 Apr 11 2006 colorls.csh
-rwxr-xr-x 1 root root 713 Apr 11 2006 colorls.sh
-rwxr-xr-x 1 root root 192 Oct 13 2004 glib2.csh
-rwxr-xr-x 1 root root 190 Oct 13 2004 glib2.sh
-rwxr-xr-x 1 root root 58 May 2 2006 gnome-ssh-askpass.csh
-rwxr-xr-x 1 root root 70 May 2 2006 gnome-ssh-askpass.sh
-rwxr-xr-x 1 root root 78 Jan 11 2006 kde.csh
-rwxr-xr-x 1 root root 74 Jan 11 2006 kde.sh
-rwxr-xr-x 1 root root 218 Feb 7 2006 krb5.csh
-rwxr-xr-x 1 root root 210 Feb 7 2006 krb5.sh
-rwxr-xr-x 1 root root 2182 Apr 21 2006 lang.csh
-rwxr-xr-x 1 root root 2470 Apr 21 2006 lang.sh
-rwxr-xr-x 1 root root 122 Jun 16 2004 less.csh
-rwxr-xr-x 1 root root 108 Jun 16 2004 less.sh
-rwxr-xr-x 1 root root 51 Nov 19 2004 mc.csh
-rwxr-xr-x 1 root root 45 Nov 19 2004 mc.sh
-rwxr-xr-x 1 root root 102 Nov 25 2004 qt.csh
-rwxr-xr-x 1 root root 99 Nov 25 2004 qt.sh
-rwxr-xr-x 1 root root 13 Aug 11 2005 vim.csh
-rwxr-xr-x 1 root root 181 Aug 11 2005 vim.sh
-rwxr-xr-x 1 root root 170 Aug 7 2004 which-2.sh


当执行完上述所有脚本之后,会执行当前帐户下的~/.bash_profile文件,该文件有其中以下内容,说明会具体执行~/.bashr的内容

引用:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi


#vi ~/.bashrc

有以下内容

引用:
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi


看来login shell最终会执行/etc/bashrc这个脚本

nologin shell

按照上面的思路可以看到nologin的执行顺序,验证的方式可在每个文件上使用echo来验证。
文章评论

共有 1 条评论

  1. tianlajiuo 于 2009-02-07 20:57:02发表:

    楼主,login shell 和 nologin shell 具体指的是什么阿,是否只是一个代名字,它怎么会去执行脚本呢? :0wl;l1