“case” command

The “case” command is used to test various conditions and execute a set of commands for each condition. Here is an example of how to use the “case” command in a shell script:

!/bin/bash
fruit=”banana”
case $fruit in
“apple”) echo “The fruit is an apple”;;
“orange”) echo “The fruit is an orange”;;
“banana”) echo “The fruit is a banana”;;
*) echo “The fruit is not apple, orange or banana”;;
esac

This script checks the value of the “fruit” variable using the “case” command. If the value is “apple”, the script prints the message “The fruit is an apple”.

“elif” command

The “elif” command is used in conjunction with the “if” command to execute a command or group of commands if a certain condition is not true, but another condition is true. Here is an example of how to use the “elif” command in a shell script:

!/bin/bash
age=15
if [ $age -ge 18 ]
then
echo “You are of legal age”
elif [ $age -ge 13 ]
then
echo “You are a teenager”
else
echo “You are a child”
fi


This script checks if the “age” variable is greater than or equal to 18. If the condition is true, the script prints the message “You are of legal age”. Otherwise, it checks if the “age” variable is greater than or equal to 13. If this condition is true, the script prints the message “You are a teenager”. Otherwise, it prints the message “You are a child”.

“else” command

The “else” command is used in conjunction with the “if” command to execute a command or group of commands if the “if” condition is not true. Here is an example of how to use the “else” command in a shell script:

!/bin/bash
age=16
if [ $age -ge 18 ]
then
echo “You are of legal age”
else
echo “You are underage”
fi


This script checks if the “age” variable is greater than or equal to 18. If the condition is true, the script prints the message “You are of legal age”. Otherwise, it prints the message “You are underage”.

“if” command

The “if” command is used to execute a command or group of commands if a given condition is true. Here is an example of how to use the “if” command in a shell script:

!/bin/bash
age=18
if [ $age -ge 18 ]
then
echo “You are of legal age”
fi

This script checks if the “age” variable is greater than or equal to 18. If the condition is true, the script prints the message “You are of legal age”.