Syntax
if [ expression ]
then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi
Example
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
Nested if-else
!/bin/bash
read -p “Enter value of i :” i
read -p “Enter value of j :” j
read -p “Enter value of k :” k
if [ $i -gt $j ]
then
if [ $i -gt $k ]
then
echo “i is greatest”
else
echo “k is greatest”
fi
else
if [ $j -gt $k ]
then
echo “j is greatest”
else
echo “k is greatest”
fi
fi