Stop on first error

Bash

Bash Problem Overview


> Possible Duplicate:
> Automatic exit from bash shell script on error

How can I have bash stop on the first command failure, without putting stuff like this all through my code?

some_prog || exit 1
some_other_prog || exit 1

Bash Solutions


Solution 1 - Bash

Maybe you want set -e:

www.davidpashley.com/articles/writing-robust-shell-scripts.html#id2382181:

> This tells bash that it should exit the script if any statement returns a non-true return value. The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. Again, for readability you may want to use set -o errexit.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatt JoinerView Question on Stackoverflow
Solution 1 - BashAlok SinghalView Answer on Stackoverflow