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

前端之家收集整理的这篇文章主要介绍了bash – 登录shell和交互式shell之间有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
什么是登录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脚本将不会读取任何启动文件

原文链接:https://www.f2er.com/bash/387824.html

猜你在找的Bash相关文章