This function should exit the calling script:
crash() {
echo error
exit 1
}
This works as expected:
echo before
crash
echo after # execution never reaches here
But this does not:
echo before
x=$(crash) # nothing is printed, and execution continues
echo after # this is printed
How do I capture the result of a function, as well as allow it to exit?
trap.