In this article, we’ll go over how to properly test exit codes in Bash scripts. Testing exit codes with $? When I first started writing Bash, I often wrote the following code to test whether a program’s execution was successful: 1some_command 2if [ "$?" -eq 0 ]; then 3 echo "It worked!" 4fiHowever, this introduces complexity in the flow of the script. For example, one minor mistake like adding en echo statement: