This Bash snippet works as expected:
$ fun1() { x=$(false); echo "exit code: $?"; }
$ fun1
exit code: 1
But this one, using local
, does not as I would have expected:
$ fun2() { local x=$(false); echo "exit code: $?"; }
$ fun2
exit code: 0
Can anyone explain why does local
sweep the return code of the command?