if syntax bash script code example
Example 1: 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
Example 2: 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