I am setting a variable like this:
myvar=$(command --params)
I want to check the exit code ($?
) of my command afterwards. Checking $?
like this always returns 0
because it successfully set the variable to the output of the command.
Is it possible to get the return value of command
?
$?
only returns 0 if the command succeeded. It's not simply "always 0 because of successful variable assignment." – Wildcard Feb 22 '17 at 17:47