bash 中`set -e` 的异常

Sol*_*dak 0 bash continuous-integration

我有一个用于制作我的项目的 bash 脚本。set -e当任何组件失败时,我在脚本的顶部中断执行。

其中一个命令会失败,但它失败是很自然的。我希望脚本的行为如下:

  • 运行脚本。
  • 到达并运行有问题的命令。
  • 如果失败,不要中断执行。仅针对此命令执行此操作。

Cyr*_*rus 5

我建议:

set +e
# your command which would fail
set -e
Run Code Online (Sandbox Code Playgroud)

或者

your_command_which_would_fail || true
Run Code Online (Sandbox Code Playgroud)