加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 登录shell和交互式shell之间有什么区别?

发布时间:2020-12-15 19:16:04 所属栏目:安全 来源:网络整理
导读:什么是登录shell和交互式shell,什么是.bash_profile和.bashrc? An interactive shell is one started without non-option arguments, unless -s is specified,without specifying the -c option,and whose input and error output are both connected to t
什么是登录shell和交互式shell,什么是.bash_profile和.bashrc?

An interactive shell is one started without non-option arguments,
unless -s is specified,without specifying the -c option,and whose
input and error output are both connected to terminals (as determined
by isatty(3)),or one started with the -i option.

An interactive shell generally reads from and writes to a user’s
terminal.

[gnu bash manual]

登录shell是您登录的shell。您可以从ps -f列表中识别登录shell,它将在程序名称开头有一个连字符,例如:

root      3561  3553  0 09:38 pts/0    00:00:00 -bash
qa        7327  3432  0 10:46 pts/1    00:00:00 -bash

交互式shell是从标准输入(通常是终端)读取命令的shell。

例如,如果您使用xterm或终端仿真器(如putty)登录bash,则会话既是登录shell又是交互式的。如果你输入bash,那么你输入一个交互式shell,但它不是一个登录shell。

如果运行shell脚本(包含shell命令的文件),那么它既不是登录shell也不是交互式shell。

启动文件在bash中高度可裁剪:

当调用登录bash shell时,/ etc / profile被提供(在当前环境中执行)。之后,检查三个文件的存在。这些文件的检查按以下顺序完成:

如果/ etc / profile存在,则source(运行)它
如果?/ .bash_profile存在,则源(运行)它
如果?/ .bash_login存在,则源(运行)它
如果?/ .profile存在,则source(运行)它

一旦找到匹配,其他文件即使存在也会被忽略。 / etc / bashrc文件可能由?/ .bash_profile和?/ .bashrc文件使用。这意味着/ etc / bashrc文件来源于bash的所有交互式调用,无论是登录或非登录shell。

所以每次请求一个新的交互式shell时,也会运行.bashrc文件。这不包括shell脚本。通常将变量,别名或函数放在此文件中。

Bash shell脚本读取不同的文件,如果适当的指示。如果用户定义(通常在自己的.bash_profile中)包含一个文件名的变量BASH_ENV,脚本将会读取。如果此变量未设置(并导出),则bash脚本将不会读取任何启动文件。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读