答案1
通常情况下,终端不会将任何选项传递给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.
交互式 shell 进一步激活其他选项。此外,根据调用名称(sh
vs 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.
结合起来,只需bash
在终端上调用即可启用这些选项。
您可以通过检查特殊变量的值来确认这一点$-
:
$ echo $-
himBH
如果您的终端设置为启动登录 shell,则可能设置一个附加选项。在这种情况下,-l
终端会将其明确作为选项传递。