There are similar questions, but mine is a little bit different. Or so I think. What I'd like to do is:
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 separate shell. So, how do I capture both, exit code and output?