Consider the following code
outer-scope.sh
#!/bin/bash
set -e
source inner-scope.sh
echo $(inner)
echo "I thought I would've died :("
inner-scope.sh
#!/bin/bash
function inner() { echo "winner"; return 1; }
I'm trying to get outer-scope.sh to exit when a call to inner() fails. Since $() invokes a sub-shell, this doesn't happen.
How else do I get the output of a function while preserving the fact that the function may exit with a non-zero exit code?