I'd like to do:
1.sh
:
#!/usr/bin/env bash
set -eu
r=0
a=$(./2.sh || r=$?)
echo "$a"
echo "$r"
2.sh
:
#!/usr/bin/env bash
echo output
exit 2
But it outputs:
$ ./1.sh
output
0 # I'd like to have `2` here
Since $(...)
runs a separate shell. So, how do I capture both, exit code and output?
1.sh
has an exit code of 0 not 2 is becauseecho "$r"
is a command that exits 0.