bash:使用 set -e 运行脚本(errexit)

标签 bash

有没有一种方法可以使用 set -e 运行 bash 脚本,也就是说,就好像 set -e 位于脚本的第一行?我知道有例如 bash -x 来模拟 set -x,但我没有看到任何可以模拟 set -e 的东西。

最佳答案

bash 可以使用任何对 set 有效的选项作为命令行选项,所以你可以简单地使用

bash -e myScript

这是手册页选项部分的第一句话(强调我的;我知道我也忽略了这句话很长时间):

In addition to the single-character shell options documented in the description of the set builtin command, bash interprets the following options when it is invoked:

关于bash:使用 set -e 运行脚本(errexit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17076342/

相关文章:

linux - 如何缩短此 grep 命令?

bash - 反引号之间的引号和奇怪的行为

linux - 如何在Launchy中输入文本并将其附加到文本文件的末尾?

php - 使用 Symfony Process 解析命令行输出

linux - 用于从单行输出中获取变量计数的 Shell 脚本

bash - bash 关联数组的基本错误值很大

bash - 在 bash 中使用带有 case 语句的 shift

json - 通过 bash 将 XML 提取为 json

mysql - BASH - 如果 $TIME 在上午 8 点到下午 1 点之间做..,esle 做.. 在 BASH 中指定时间变量和 if 语句

linux - [[ ]] 中的 Bash == 运算符太聪明了!