I was using \"exit 1\" statement in my bash functions to terminate the whole script and it worked fine:
function func() { echo \"Goodbye\" exit 1 } ech
I guess better is
#!/bin/bash set -e trap "exit 1" ERR myfunc() { set -x # OPTIONAL TO SHOW ERROR echo "Exit with failure" set +x # OPTIONAL exit 1 } echo "BEFORE..." myvar="$(myfunc)" echo "AFTER..But not shown"