Showing posts with label Different ways to implement numerical comparisons using if else in bash. Show all posts
Showing posts with label Different ways to implement numerical comparisons using if else in bash. Show all posts

Wednesday, November 30, 2022

Different ways to implement numerical comparisons using if else in bash

 #!/usr/bin/bash
echo "enter a number"
read num
if [[ $num -ge 1 ]] && [[ $num -lt 10 ]]
then
echo "A"
elif [[ $num -ge 10 ]] && [[ $num -lt 90 ]]
then
echo "B"
elif [[ $num -ge 90 ]] && [[ $num -lt 100 ]]
then
echo "C"
else
echo "D"
fi


#!/bin/bash
echo "enter a number"
read num
if (( num >= 1)) && ((num<10))
then
echo "sam"
elif ((num >= 10)) && ((num < 90 ))

then
echo "ram"
elif ((num >= 90)) && ((num  <100))
then
echo "rahim"
else
echo "tara"
fi

#!/bin/bash
echo "enter a number"
read num
if [ $num -ge 1 ] && [ $num -lt 10 ]
then
echo "A"
elif [ $num -ge 10 ] && [ $num -lt 90 ]
then
echo "B"
elif [ $num -ge 90 ] && [ $num -lt 100 ]
then
echo "C"
else
echo "D"
fi