What version of bash
are you using? The capture of the output has zero effect on the return code with my version, 4.1.5
:
pax> false; echo $?
1
pax> echo $?
0
pax> x=$(false 2>&1) ; echo $?
1
It's not always a good idea to rely on standard error being non-empty to detect errors. Many programs don't output errors but rely solely on the return code.