Bash: If, Else If, Else Examples

here are some examples of if, else if, else statements in bash:

# Check if the variable is set
if [ -z "$variable" ]; then
  echo "The variable is not set."
else
  echo "The variable is set."
fi

# Check if the value of the variable is equal to 1
if [ "$variable" -eq 1 ]; then
  echo "The variable is equal to 1."
elif [ "$variable" -eq 2 ]; then
  echo "The variable is equal to 2."
else
  echo "The variable is not equal to 1 or 2."
fi

# Check if the value of the variable is greater than 10
if [ "$variable" -gt 10 ]; then
  echo "The variable is greater than 10."
else
  echo "The variable is not greater than 10."
fi

You can also use if, else if, else statements to control the flow of your script. For example, you could use them to check if a user has entered a valid input or to execute different commands depending on the outcome of a test.