The*_*mer 23 linux bash shell command-line
所以bash 手册页解释了什么是登录和交互式 shell:
登录 shell 是参数零的第一个字符是 - 或以 --login 选项开头的 shell。
交互式 shell 是一个没有非选项参数并且没有 -c 选项的启动,其标准输入和错误都连接到终端(由 isatty(3) 确定),或者一个以 -i 选项启动。如果 bash 是交互式的,则设置 PS1 并且 $- 包括 i,允许 shell 脚本或启动文件测试此状态。
我认为这意味着我们可以有 4 种不同类型的 shell:
但是为什么我们首先要有交互式/非交互式和登录/非登录 shell?为什么品种多?如果我们只有一种壳,我们会失去什么?
此外,当试图通过运行确定我是否在登录 shell 中时echo $-
,它输出:
himBH
Run Code Online (Sandbox Code Playgroud)
关于这些标志的解释这里,但是h
,H
和m
没有解释。有没有描述所有这些标志的地方?
mpy*_*mpy 21
这些是我对不同“类型”shell 的想法——不幸的是,我没有从一开始就目睹 Un*x 的兴起(我认为这个概念在历史上已经发展到一个很好的范围),所以请批评一下。
/etc/profile
,~/.bash_login
等等,请参考手册的准确名单)只能由源登录炮弹。~/.bash_logout
在登录shell 存在时运行备份脚本。~/.bashrc
,因为我希望我的键绑定与 shell 交互——因此这是一个交互式的、非登录外壳。bash
应该尽可能快地启动,即不应该读取任何配置文件。这是一个非交互式、非登录的 shell。所以,我对你的问题的回答如果我们只有一种类型的外壳,我们会失去什么?一句话概括:“灵活性”。
你的第二个问题的答案很简单:
$-
列出当前的选项集。这些可以通过命令行参数设置bash
或通过set
内置。所以你必须看手册中的两个地方:
OPTIONS
部分:
-i If the -i option is present, the shell is interactive.
Run Code Online (Sandbox Code Playgroud)SHELL BUILTIN COMMANDS
部分,小节set
:
-h Remember the location of commands as they are looked up for execution. This is enabled by default.
-m Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that sup?
port it (see JOB CONTROL above). Background processes run in a separate process group and a line containing
their exit status is printed upon their completion.
-B The shell performs brace expansion (see Brace Expansion above). This is on by default.
-H Enable ! style history substitution. This option is on by default when the shell is interactive.
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
7075 次 |
最近记录: |