 <p>Note also, each command's exit status is stored in the shell variable $?, which you can check immediately after running the command. A non-zero status indicates failure:</p> <pre><code>my_command if [ $? -eq 0 ] then echo "it worked" else echo "it failed" fi </code></pre>