Title: Shell.Scripting.Exit.Results
Created: 2012-10-23 04:33:02 +0000

Bash shell scripting notes – Determining a Command’s Exit Result

Say you want to know if a command in a shell script executed successfully, how do you test it’s exit code in a shell script?

touch some.file
if [ "$?" = "0" ]; then
   # success here
   echo "touch command worked"
else
   # failure here
   echo "could not touch some.file"
fi