last command exit status

From thelinuxwiki
Jump to: navigation, search

useful in bash to execute a command based on the previous command's exit status

if [ $? == 0 ]; then 
  echo "last command worked dude! exit status was 0"
fi
if [ $? == 1 ]; then 
  echo "last command failed dude! exit status was 1"
fi