我正在编写一个 bash 脚本,它应该退出最后一个失败命令的错误代码,而不是继续执行。这可以通过在|| exit $?任何地方添加 a 来实现,但是有没有更简单的方法,例如set在开始时有一个选项来做到这一点而不会丑化每一行?
Chr*_*ard 18
set -e ?
set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
Set or unset values of shell options and positional parameters.
Change the value of shell attributes and positional parameters, or
display the names and values of shell variables.
Options:
-a Mark variables which are modified or created for export.
-b Notify of job termination immediately.
-e Exit immediately if a command exits with a non-zero status.
...
Run Code Online (Sandbox Code Playgroud)