We have already described few shell scripts and this post explain simple if else, and Elif statements with small example. This condition statement used to depending on whether certain conditions are true.
Simple FI... Else... FI
The below script does not require two parameters, Just pass value when execute.
The first condition is true command1 is executed otherwiase goes not command2
#!/bin/bash
if [ "$1" = "linuxfaq" ]
then
echo "Yes,linuxfaq"
else
echo "No, Not linuxfaq"
fi
IF... Elif... Else... FI
Check multiple condtion with an areguments
#!/bin/bash
echo "=====COUNTRY LIST======="
echo "ISO Code's are:"
echo "IN = India"
echo "US = USA"
echo "UKR= Ukraine"
echo "Choose your Country List"
read COUNTRY
if [ $COUNTRY = IN ]
then
echo "You have Selected" $COUNTRY
elif [ $COUNTRY = US ]
then
echo "You have Selected" $COUNTRY
elif [ $COUNTRY = UKR ]
then
echo "You have Selected" $COUNTRY
else
echo "Choose any one Country Name?";
fi
Output :
=====COUNTRY LIST=======
ISO Code's are:
IN = India
US = USA
UKR= Ukraine
Choose your Country List: IN
"You have Selected India.
Comments (0)