登录外壳程序和交互式外壳程序有什么区别? [英] What are the differences between a login shell and interactive shell?

查看:123
本文介绍了登录外壳程序和交互式外壳程序有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是login shellinteractive shell,什么是.bash_profile.bashrc?

推荐答案

交互式shell是一个没有非选项参数的启动, 除非指定了-s,但未指定-c选项,并且其 输入和错误输出均连接到端子(确定 isatty(3)),或者以-i选项开头的

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手册]

登录外壳是您登录的外壳.您可以从ps -f列表中识别出登录shell,程序名称的开头将带有连字符,例如:

A login shell is a shell where you login. You can recognize a login shell from a ps -f listing, it will have a hyphen at the start of the program name, for example:

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

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

An interactive shell is one which reads commands from it's standard-input, usually a terminal.

例如,如果您使用xterm或终端仿真器(如putty)登录bash,则会话既是登录外壳又是交互式外壳.如果然后键入bash,则输入一个交互式外壳程序,但它不是登录外壳程序.

For example, if you login to bash using an xterm or terminal emulator like putty, then the session is both a login shell and an interactive one. If you then type bash then you enter an interactive shell, but it is not a login shell.

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

If a shell script (a file containing shell commands) is run, then it is neither a login shell nor an interactive one.

启动文件可以在bash中进行高度定制:

Start-up files are highly tailorable in bash:

当调用登录bash shell时,将生成/etc/profile(在当前环境中执行).之后,检查三个文件是否存在.这些文件的检查按以下顺序进行:

When a login bash shell is invoked, then /etc/profile is sourced (executed in the current environment). After that, three files are checked for existence. The checks for these files are done in this order:

如果/etc/profile存在,请提供(运行)它
如果~/.bash_profile存在,则源(运行)它
如果~/.bash_login存在,则源(运行)它
如果~/.profile存在,则源(运行)它

if /etc/profile exists, source (run) it
if ~/.bash_profile exists, source (run) it
if ~/.bash_login exists, source (run) it
if ~/.profile exists, source (run) it

一旦找到匹配项,其他文件将被忽略,即使它们存在也是如此. /etc/bashrc文件可能同时被~/.bash_profile~/.bashrc文件使用.这意味着/etc/bashrc文件源自bash的所有交互式调用,无论它是登录外壳程序还是非登录外壳程序.

Once a match is found, the other files are ignored, even if they exist. The /etc/bashrc file might be used by both the ~/.bash_profile and the ~/.bashrc files. That would mean that the /etc/bashrc file is sourced on all interactive invocations of bash, whether it is a login or non-login shell.

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

So, the .bashrc file is also run every time you request a new interactive shell. This does not include a shell script. Normally variables, aliases or functions are placed in this file.

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

Bash shell scripts read a different file if suitably instructed. If the user defines (usually in their own .bash_profile) a variable BASH_ENV which contains a filename, scripts will read this. If this variable is not set (and exported) then bash scripts will not read any startup files.

这篇关于登录外壳程序和交互式外壳程序有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆