bash_scripting

This is an old revision of the document!


Bash Scripting

Conditionals

  • The ? variable has the exit/return value of the last program that ran.
if [ $? -eq 0 ]; then
  echo "All is well."
  exit 0
elif [ $? -eq 1 ]; then 
  echo "Doh!"
  exit 1
else
 echo "Really?!"
 exit 2
fi

One line if statement

if [$? -eq 0]; then echo "Error"; else echo "OK"; fi
  • bash_scripting.1493132947.txt.gz
  • Last modified: 2017/04/25 15:09
  • by mgupton