为什么 bash 命令手册中没有 -e 选项?

bob*_*lan 14 bash man

我对 bash 手册中缺少的 -e 选项有点困惑。man bash

但它正在使用像 : 这样的脚本 shebang,#!/bin/bash -e当然它是在help set.

为什么 bash 手册的选项中没有列出它?

Kus*_*nda 22

在手册的开头就隐含地提到了这一点:

选项内置命令
描述中记录的所有单字符 shell 选项set(包括-o)都可以在调用 shell 时用作选项。[...]

set然后,您需要在手册中进一步查找内置命令,help set在交互式 shell 会话中使用(正如您在问题中提到的那样),或者以某种适当的方式访问较长的参考手册(例如,通过info bash set在系统上使用命令)这是可行的)。


小智 9

它位于 bash(1) 手册页中set。在某些系统上,包括基于 Debian 的系统,您还会发现 bash-builtins(7) 甚至builtins(7) 手册页,其中仅涵盖该 shell 的内置命令,在其中可能更容易找到信息。

\n\n
\n

...

\n
  -e      Exit immediately if a pipeline (which may consist  of  a\n          single  simple  command),  a list, or a compound command\n          (see SHELL GRAMMAR above), exits with a non-zero status.\n          The  shell  does  not  exit if the command that fails is\n          part of the command list immediately following  a  while\n          or  until  keyword, part of the test following the if or\n          elif reserved words, part of any command executed  in  a\n          &&  or || list except the command following the final &&\n          or ||, any command in a pipeline but the last, or if the\n          command\'s  return  value is being inverted with !.  If a\n          compound command other than a subshell  returns  a  non-\n          zero  status because a command failed while -e was being\n          ignored, the shell does not exit.  A  trap  on  ERR,  if\n          set,  is  executed  before the shell exits.  This option\n          applies to the shell environment and each subshell envi\xe2\x80\x90\n          ronment  separately  (see  COMMAND EXECUTION ENVIRONMENT\n          above), and may cause subshells to exit before executing\n          all the commands in the subshell.\n\n          If  a  compound  command or shell function executes in a\n          context where -e is being ignored, none of the  commands\n          executed  within  the  compound command or function body\n          will be affected by the -e setting, even if  -e  is  set\n          and  a  command returns a failure status.  If a compound\n          command or shell function sets -e while executing  in  a\n          context  where -e is ignored, that setting will not have\n          any effect until the compound  command  or  the  command\n          containing the function call completes.\n
Run Code Online (Sandbox Code Playgroud)\n

...

\n
  errexit Same as -e.\n
Run Code Online (Sandbox Code Playgroud)\n

...

\n
\n

  • 是的,但是内置 `set` 的描述并没有说它的选项可以在启动时作为选项提供给 shell。许多其他内置函数也采用选项,但这些选项不能作为 shell 本身的选项给出(它们也没有意义)。“set”选项不同的事实需要从其他地方获取。(例如在“选项”部分下)。 (2认同)