On Fri, Oct 02, 2015 at 02:09:21PM +0300, Christoph Gysin wrote: > Since set -e does not work, it means I have to postfix every command > with "|| exit $?": > > f() { > some command || exit $? > more commands --with-args || exit $? > } > > output=$(f)
Since it's a function, I would recommend return instead of exit. Also, you don't need the $? there. exit (or return) with no arguments will retain the exit status of the previous command. > My understanding was the the whole point of set -e was to have that > behaviour by default for every command (with the documented > exceptions). That was the INTENT, perhaps, of the original designers way back in the ancient Bourne shell days, but that is never how it WORKED in real life. The crazy shell command syntax just made it too quirky and unreliable. So they made exceptions, and then exceptions to the exceptions, and so on until we have the current unusable mess. Putting "|| return" or "|| exit" after all critical commands in your script is precisely what you should do. (Some people write a die() function and then use "|| die 'my message'" instead.)