I'm writing a bash script that should exit the error code of the last failed command and not continue execution. This can be achieved by adding a || exit $? everywhere, but is there an easier way, e.g. a set option at the start to do this without uglifying every line?
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
| add comment (requires an account with 50 reputation) |
|
set -e ?
|
|||||||||||||
|
|
You might join all the commands with
if there is no
Best regards, Krzysztof |
|||||
|

exit $?is not needed. By default, your script will exit with the $? of the last command.exit $?andexitare equivalent in bash. – jordanm Oct 17 '12 at 17:55$?was superfluous? Theexititself (withoutset -eas I learned) was necessary. But thanks, good to know for situations where I don't want to abort on all errors. – Tobias Kienzler Oct 17 '12 at 17:58$?is superfluous. – jordanm Oct 17 '12 at 19:25