An example of the simplest form of an if-statement would be:
count=5
if [ $count == 5 ]
then
echo "$count"
fi
The "echo" statement prints its argument, in this case the value of the variable "count", to the terminal window. Indentation of the code between the keywords of the if-statement improves readability, but is not necessary.
If you have a situation where a piece of code should be executed only if a condition is not true, you can use the keyword "else" in a if-statement, as in this example:
count=5
if [ $count == 5 ]
then
echo "$count"
else
echo "count is not 5"
fi
If you want to differentiate between multiple conditions, you can use the keyword "elif", which is derived from "else if", as in this example:
if [ $count == 5 ]
then
echo "count is five"
elif [ $count == 6 ]
then
echo "count is six"
else
echo "none of the above"
fi
As you may have guessed, you can have any number of "elif" clauses. An example with multiple "elif" conditions would be:
if [ $count == 5 ]
then
echo "count is five"
elif [ $count == 6 ]
then
echo "count is six"
elif [ $count == 7 ]
then
echo "count is seven"
elif [ $count == 8 ]
then
echo "count is eight"
elif [ $count == 9 ]
then
echo "count is nine"
else
echo "none of the above"
fi
case "$count" in
5)
echo "count is five"
;;
6)
echo "count is six"
;;
7)
echo "count is seven"
;;
8)
echo "count is eight"
;;
9)
echo "count is nine"
;;
*)
echo "none of the above"
esac
count=1
done=0
while [ $count -le 9 ]
do
sleep 1
(( count++ ))
if [ $count == 5 ]
then
continue
fi
echo "$count"
done
echo Finished
See also the section on How to Pass Arguments to a Bash Script, which shows how to use conditionals to process parameters passed from the command line.
The Bash shell provides other programming constructs, such as for-loops, while-loops, and arithmetic expressions.

