The IF condition is used to take decision in scripting i.e., used to execute blocks of code based on the given condition which evaluates to true or false.
//command X executes when condition is true
//command Y executes when condition is false
If loop – Using Integer comparison
if [ $x -eq 1 ]
echo "value of x is 1"
If - else - if loop – Using String comparison
if [ $name == "test" ]
echo "Name is test"
elif [ $name == "test1" ]
echo "Name is test1"
echo "Name is $name"
If loop – Using test command
Test command is used to check whether the given expression is true or false.
if test $x > 5
echo "Input Value is greater than 5"
echo "Input Value is lesser than 5"