登录shell和交互shell之间的差异 [英] differences between login shell and interactive shell

查看:166
本文介绍了登录shell和交互shell之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好'我有一个关于linux.Before壳问题问它,我想说,我真的因特网上大量搜索。然而,因为我对Linux新手这些都没有给我任何的想法。现在,这里是我的问题。什么是登录shell 交互式shell 。除了这个,我不知道什么是的.bash_profile 的.bashrc 。我通过他们花了几个小时,但我仍没有他们的身影在out.Thanks提前

Hi everyone' I have a question about shell in linux.Before asking it I would like to say that I really made lots of search on internet however since I'm newbie on linux these are not give me any idea. Now here is my question. What is login shell and interactive shell. In addition to this, I wonder what is .bash_profile .bashrc.I spent a couple hours through them but still I have not figure them out.Thanks in advance

推荐答案

一个的登录shell 的是你登录一个shell!您可以识别从 PS -f 房源登录shell,它会在程序名的开头连字符,例如:

A login shell is a shell where you login! You can recognise 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

这是交互式shell 的是其中一个读命令,从它的标准输入,通常一个终端。

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

例如,如果您登录使用xterm或终端仿真器,比如腻子来砸,则会话既是一个登录shell和一个交互。如果然后键入庆典然后你进入一个交互式shell,但它不是一个登录shell。

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,也没有一个交互。

A shell script (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,那么 / etc / profile文件的来源(在当前的环境中执行)。在此之后,三个文件被检查存在。这些文件的检查以该顺序进行,在情况下,它们不以不同的顺序源彼此

When a login bash 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, in case they do not source each other in a different 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的所有交互调用,无论是登录还是非登录shell。

Once the 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.

因此​​,的.bashrc 文件也运行每次你申请一个新的交互式shell时间的。这不包括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.

这篇关于登录shell和交互shell之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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