Saving an Exit Status
Why does this always print status: 0, even when deploy fails?
status: 0
deploy
deploy echo "deploy finished" echo "status: $?"
Choose one answer
deploy must be called with exit for its status to be kept.
exit
$? holds the status of the last command, here the first echo.
$?
echo
$? is only set for commands that run in the background.
echo resets $? to zero at the start of every script.