/etc/profile、~/.bash_profile、~/.bashrc和/etc/bashrc

一、读取关系

文件 引用关系 读取shell
/etc/profile   login shell
~/.bash_profile 引用~/.bashrc login shell
~/.bashrc 引用/etc/bashrc login shell、non-login shell
/etc/bashrc   login shell、non-login shell

 

 

 

 

 

 

 

二、名字解释

interactive shell:交互式shell。可以通过echo $-查看是否含有i来判断是否为交式式shell。

non-interactive shell:非交互式shell。可以通过echo $-查看是否不含有i来判断是否为非交式式shell。

login shell:登录shell。可通过echo $0看是否为-bash,或者shopt login_shell是否为on来判断是否为登录shell。

non-login shell:非登录shell。可通过echo $0看是否为bash,或者shopt login_shell是否为off来判断是否为登录shell。

 

我们在这里只是给出了区分的技术方法,并没有说,“需要用户名密码登录进去的shell就是登录shell”,“可以交互式输入输出的shell就是交互式shell”。

因为这种定义一般是这样,但“不一般”的情况下反倒会让人很疑惑。比如你用python paramiko库用用户名密码去登录机器,你却不是登录shell; 你也实现交互式输入输出,你却也不是交互式shell。

交互式shell和非交互式shell的本质区别是,是否绑定一套标准输入输出设备(即有tty),进行输入输出。这由调用时shell参数决定。

登录shell和非登录shell的本质区别是,读取哪些环境变量文件的区别。这由调用时shell参数决定。

 

三、who am i没有输出问题探讨

who am i 等同于who -m,显示关联标准输入的用户,即交互式shell的用户。只要你最开始是一个交互式shell,那么就会关联标准输入,即便你后边切换其他用户创建非登录shell,这种关联关系仍然存在。

who am i没有输出那就说明没有关联标准输入的用户,那就明包括当前shell和最开始的祖先shell,都不是交互式shell。

关联标准输入,也即有tty值:

A tty is a native terminal device, the backend is either hardware or kernel emulated.

A pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm, screen, or ssh are such programs). 

A pts is the slave part of a pty.

 

posted on 2017-04-06 15:18  诸子流  阅读(488)  评论(0编辑  收藏  举报