Answers for "bash if else if"

26

else if statement bash syntax

#!/bin/bash
 
read -p "Enter your marks: " marks
 
if [ $marks -ge 80 ]
then
    echo "Very Good"
 
elif [ $marks -ge 50 ]
then
    echo "Good"
 
elif [ $marks -ge 33 ]
then
    echo "Just Satisfactory"
else
    echo "Not OK"
fi
Posted by: Guest on March-29-2020
23

bash if statement

and - &&
or - ||

# and example
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi

# or example
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
then
ls -alh
else
ls
fi
Posted by: Guest on February-21-2020
3

if else statement example in shell script

if [ ... ]
then
  # if-code
else
  # else-code
fi
Posted by: Guest on May-08-2021
2

bash if

#!/bin/bash

foo="qux"
bar="qux"

if [ "$foo" = "$bar" ]; then
    echo "The strings are equal."
else
    echo "The strings aren't equal."
fi
Posted by: Guest on September-14-2020
4

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
Posted by: Guest on November-12-2020
0

bash if else if

if [[ TEST-COMMAND ]]
then
  STATEMENTS1
else
  STATEMENTS2
fi
Posted by: Guest on November-03-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language