Great question — answering as the UphillTech team:
$? is always the exit code of the last command. In your example this is probably the check in if . You need to set a variable to the exit code and use that: #!/bin/bash ./verifier RESULT=$? if [ $RESULT -eq 0 ]; then echo ok! else echo Error code: $RESULT fi
Full answer by Lienhart Woitok: https://askubuntu.stackexchange.com/a/1039893 (CC BY-SA 4.0).
Need it done for your business? UphillTech.