sh else if code example

Example 1: if else statement example in shell script

if [ ... ]
then
  # if-code
else
  # else-code
fi

Example 2: bash else if

if [ "$animal" == "penguin" ]; then
  echo "Hmmmmmm fish... Tux happy!"
elif [ "$animal" == "dolphin" ]; then
  echo "Pweetpeettreetppeterdepweet!"
else
  echo "*prrrrrrrt*"
fi

if TEST-COMMANDS; then
  CONSEQUENT-COMMANDS;
elif MORE-TEST-COMMANDS; then
  MORE-CONSEQUENT-COMMANDS;
else
  ALTERNATE-CONSEQUENT-COMMANDS;
fi

Example 3: bash if else if

if [[ TEST-COMMAND ]]
then
  STATEMENTS1
else
  STATEMENTS2
fi