以下是一些常见的形式。最佳选择取决于您的工作。您可以在单个脚本中使用任何子集或它们的组合,而不会造成不良影响。
if ! failingcommandthen echo >&2 message exit 1fi
failingcommandret=$?if ! test "$ret" -eq 0then echo >&2 "command failed with exit status $ret" exit 1fi
failingcommand || exit "$?"
failingcommand || { echo >&2 "failed with $?"; exit 1; }


