last command exit status

From thelinuxwiki
Revision as of 16:47, 31 May 2014 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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