Slo*_*rks 4 command-line bash scripts
我发现的是,默认的shell,当我启动终端(与我用Ctrl+ Alt+ T)是/bin/bash。
type -p bash
Run Code Online (Sandbox Code Playgroud)
返回结果为:
/bin/bash
Run Code Online (Sandbox Code Playgroud)
这表明相同的可执行文件时,我做的是运行Ctrl+ Alt+T或说bash。
这个 shell 与命令调用相同bash,它的一些选项传递给它,对吗?如果是,这些选项是什么?
例如,也许该-i选项被传递以使 bash shell 具有交互性?
PS:也许这也有关系,但我似乎无法在这里拼凑所有的碎片。
通常,不,终端不会将任何选项传递给bash. bash但是,它会根据调用方式假定一组默认选项。从man bash, 部分INVOCATION:
An interactive shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as determined by isatty(3)), or one started with the -i
option. PS1 is set and $- includes i if bash is interactive, allowing
a shell script or a startup file to test this state.
Run Code Online (Sandbox Code Playgroud)
交互式外壳进一步激活其他选项。此外,一些默认值基于调用名称 ( shvs bash) 应用。阅读(部分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
support it (see JOB CONTROL above)
-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)
结合起来,只需bash在终端上调用即可启用这些选项。
您可以通过检查$-特殊变量的值来确认这一点:
$ echo $-
himBH
Run Code Online (Sandbox Code Playgroud)
另一个可能设置的选项是您的终端是否设置为启动登录 shell。在这种情况下-l,终端显式地将其作为选项传递。
| 归档时间: |
|
| 查看次数: |
366 次 |
| 最近记录: |