是否有任何可以调用它的 bash 选项?

是否有任何可以调用它的 bash 选项?

寻找Ctrl当我启动终端(使用++ Alt)时使用的默认 shellT/bin/bash

并运行内置命令typebash作为:

type -p bash

返回结果为:

/bin/bash

建议当我执行Ctrl++或说时运行相同的可执行文件。AltTbash

此 shell 与调用命令相同bash是否已将某些选项传递给它?如果是,这些选项是什么?

举个例子,也许-i传递这个选项是为了使 bash shell 具有交互性?

附言:也许吧也相关,但我似乎无法将所有部分拼凑在一起。

答案1

通常情况下,终端不会将任何选项传递给bashbash但是,它会根据调用方式假设一组默认选项。从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 进一步激活其他选项。此外,根据调用名称(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.

结合起来,只需bash在终端上调用即可启用这些选项。

您可以通过检查特殊变量的值来确认这一点$-

$ echo $-
himBH

如果您的终端设置为启动登录 shell,则可能设置一个附加选项。在这种情况下,-l终端会将其明确作为选项传递。

相关内容