If I assign the output of a command substitution to a local variable, how do I get the exit status of the command?
This is the behaviour of ZSH 5.8:
false; echo $? # output is 1 as expected
foo=$(false); echo $? # output is 1 as expected
local foo=$(false); echo $? # output is 0
local foo=$(false) status=$?
works to save the exit status of the subshell – Moh Sep 17 '23 at 05:07