【问题标题】:What does '#!/bin/sh -xe' mean? [duplicate]'#!/bin/sh -xe' 是什么意思? [复制]
【发布时间】:2019-05-03 15:07:06
【问题描述】:

Tribler 的GitHub 存储库中,我看到file 带有解释器:#!/bin/sh -xe

在 Mac 和 Linux 上,man sh 重定向到 BASH(1)(与 man bash 相同)。

在这个 man 文件中,在以下部分:

选项

,没有提到选项-x,也没有提到选项-e

解释器#!/bin/sh -xe是什么意思?

【问题讨论】:

  • 对于-ethis answer
  • OPTIONS 会话中的第一行表示您可以在启动bash 时使用内置set 下记录的所有选项(包括-x-e)。后面的标志只是附加标志。=

标签: bash sh


【解决方案1】:

我发现了这个:

man sh:

-x xtrace        Write each command to standard error (preceded by
                            a ‘+ ’) before it is executed.  Useful for debug‐
                            ging.


-e errexit       If not interactive, exit immediately if any
                            untested command fails.  The exit status of a com‐
                            mand is considered to be explicitly tested if the
                            command is used to control an if, elif, while, or
                            until; or if the command is the left hand operand
                            of an “&&” or “||” operator.

似乎这些只是错误控制选项,可确保在命令失败时不会发生更糟的情况。

【讨论】:

  • 请注意,使用-e 可能会非常适得其反,在不存在的地方产生错误;请参阅BashFAQ #105 中的练习,以及in-ulm.de/~mascheck/various/set-e 中不同 shell 如何处理此标志之间的不兼容列表
【解决方案2】:

每个手册页:read more

-a、-b、-C、-e、-f、-m、-n、-o 选项、-u、-v 和 -x 选项在 Special Built 中描述为 set 实用程序的一部分-在实用程序中。从 set special built-in 派生的选项字母也应接受带有前导加号 ('+') 而不是前导连字符(表示 IEEE Std 1003.1-2001 本卷中描述的选项的相反情况) .

当您阅读 set 手册页时,您会得到:

-x 在扩展命令之后和执行之前,shell 应将每个命令的跟踪写入标准错误。未指定是否跟踪关闭跟踪的命令。

-e 当此选项打开时,如果简单命令由于 Shell 错误的后果中列出的任何原因而失败或返回退出状态值 >0,并且不是复合命令的一部分list 跟在 while、until 或 if 关键字之后,并且不是 AND 或 OR 列表的一部分,也不是前面有 ! 的管道保留字,则shell将立即退出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 2022-01-25
    • 2019-09-12
    • 2015-01-22
    相关资源
    最近更新 更多