登陆shell和非登陆shell区别

An interactive login shell is started after a successful login, using /bin/login, by reading the /etc/passwd file. This shell invocation normally reads /etc/profile and its private equivalent ~/.bash_profile upon startup.
An interactive non-login shell is normally started at the command-line using a shell program (e.g., [prompt]$/bin/bash) or by the /bin/su command. An interactive non-login shell is also started with a terminal program such as xterm or konsole from within a graphical environment. This type of shell invocation normally copies the parent environment and then reads the user's ~/.bashrc file for additional startup configuration instructions.
A non-interactive shell is usually present when a shell script is running. It is non-interactive because it is processing a script and not waiting for user input between commands. For these shell invocations, only the environment inherited from the parent shell is used.
The file ~/.bash_logout is not used for an invocation of the shell. It is read and executed when a user exits from an interactive login shell

没有发现翻译,自己来翻译下吧:

通过/bin/login程序,读取/etc/passwd文件,成功登录后,就会启动一个交互式登录 shell。启用这样的Shell,通常在开启的时候会读取/etc/profile还有用户自己的~/.bash_profile文件。

交互式非登录shell,通常是通过命令行使用shell程序(比如/bin/bash)或者使用命令/bin/su。交互式非登录shell也会随着图形界面中的终端程序(比如xterm和konsole)启动而启动。启动这种类型的shell通常是copy了父环境(译者注:他的意思应该是使用了父用户的环境变量)并且读取用户自己的~/bashrc文件作为启动此shell的配置。

非交互式shell通常在运行shell脚本时候表现出来。之所以称之为非交互,是因为它正在运行脚本,而且脚本的命令中间不需要用户输入。对于这样的shell调用,只会使用继承自父shell的环境。

在调用shell时,~/.bash_logout文件并不会被使用。只有当用户退出一个交互式登录shell时才会被读取和执行

 

顺便在转载一些更深入一点点的内容

Bash下每个用户都可以配置两个初始文件:.bash_profile和.bashrc。man bash中的相关解
释如下:

,------------------------------------------------------------
| ~/.bash_profile
| The personal initialization file, executed for login shells
| ~/.bashrc
| The individual per-interactive-shell startup file
`------------------------------------------------------------

以前一直没细想两者的区别,今天整理了一下。

* 每次bash作为login shell启动时会执行.bash_profile。

主要有(我所知道的)有以下几种情形:

a) 每次登录到服务器时默认启动的shell

b) “su -l [USER]”时进入的shell

c) “bash --login”进入的shell

* 每次bash作为普通的交互shell(interactive shell)启动时会执行.bashrc

常见的有:

i) “su [USER]”进入的shell
ii) 直接运行“bash”命令进入的shell。

** 注意

1, 在shell脚本中“#!/usr/bin/bash”启动的bash并不执行.bashrc。因为这里的bash不是
interactive shell。

2, bash作为login shell(login bash)启动时并不执行.bashrc。虽然该shell也是interactive shell,
但它不是普通的shell。

* 一般.bash_profile里都会调用.bashrc

尽管login bash启动时不会自动执行.bashrc,惯例上会在.bash_profile中显式调用.bashrc。

,-------------------------------------
| if [ -f ~/.bashrc ]; then
| . ~/.bashrc
| fi
`-------------------------------------

总结一下就是:

~/.bash_profile 是交互式、login 方式进入 bash 运行的
~/.bashrc 是交互式 non-login 方式进入 bash 运行的
通常二者设置大致相同,通常前者会调用后者。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值