I currently use this function to wrap executing commands and logging their execution, and return code, and exiting in case of a non-zero return code.
However this is
Additional to "$@"
what Douglas says, i would use
return $?
And not exit
. It would exit your shell instead of returning from the function. If in cases you want to exit your shell if something went wrong, you can do that in the caller:
do_cmd false i will fail executing || exit
# commands in a row. exit as soon as the first fails
do_cmd one && do_cmd && two && do_cmd three || exit
(That way, you can handle failures and then exit gracefully).