有没有办法向 bash 添加错误处理程序,如果脚本中的任何给定命令失败,该错误处理程序就会执行?
我知道set -o errexit
,但这不允许我添加自定义错误处理程序。
答案1
set -e
trap "do your custom stuff here" EXIT
...
# now whenever there's an error condition, due to the set -e, the script will exit
# and upon this exit, the trap custom message shall be activated.