shell script exit if any command fails

dd this to the beginning of the script:html

set -e

This will cause the shell to exit immediately if a simple command exits with a nonzero exit value. A simple command is any command not part of an if, while, or until test, or part of an && or || list.linux

See the bash(1) man page on the "set" internal command for more details.shell

I personally start almost all shell scripts with "set -e". It's really annoying to have a script stubbornly continue when something fails in the middle and breaks assumptions for the rest of the script.bash

相關文章
相關標籤/搜索