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?
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 $?
andexit
are equivalent in bash. – jordanm Oct 17 '12 at 17:55$?
was superfluous? Theexit
itself (withoutset -e
as 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