posted Oct 9, 2011, 5:35 AM by Neil Mathew
[
updated Oct 9, 2011, 6:54 AM
]
It is a control statement used for decision making.
Syntax:
if [ $<variable> <logical operator> $<variable>
then
<statement>
fi
Example:
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "$a is the greatest!"
fi
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "$a is the greatest!"
elif [ $b -gt $a ] && [ $b -gt $c ]; then
echo "$b is the greatest!"
else
echo "$c is the greatest!"
fi