有没有一种方法可以使用 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/