'#!/ bin / sh -xe'是什么意思?

时间:2018-12-01 20:35:42

标签: bash sh

Tribler的GitHub上的存储库中,我看到带有解释器#!/bin/sh -xe的{​​{3}}。

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

在此手册文件中的以下部分:

  

选项

,没有提及选项-x或选项-e

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

2 个答案:

答案 0 :(得分:3)

我发现了:

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.

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

答案 1 :(得分:1)

每手册页:read more

  

在特殊构建中,将-a,-b,-C,-e,-f,-m,-n,-o选项,-u,-v和-x选项描述为set实用程序的一部分。 -在实用程序中。从设置的特殊内置选项衍生的选项字母也应使用前导加号('+')代替前导连字符(表示该选项的相反情况,如IEEE Std 1003.1-2001的本卷中所述)

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

  

-x 在扩展命令之后和执行命令之前,外壳程序应将每个命令的跟踪信息写入标准错误。尚未确定是否跟踪了关闭跟踪的命令。

  

-e 启用此选项时,如果一个简单命令由于“ Shell错误的后果”中列出的任何原因而失败,或者返回退出状态值> 0,并且不属于此组合, list在一会儿,直到或if关键字之后,并且不是AND或OR列表的一部分,也不是前面带有!的管道。保留字,那么外壳应立即退出。

相关问题