Shell script to find greatest of two numbers

Let's write a shell script to find the greatest of two numbers.




Algorithm

1. Get two numbers. Say num1, num2

2. If num1 > num2

     echo value of num1

3. Otherwise,

     echo value of num2




Shell script for finding greatest of two numbers

#shell script to find the greatest of two numbers

echo "Enter Num1"
read num1
echo "Enter Num2"
read num2

if [ $num1 -gt $num2 ]
then
    echo $num1
else
    echo $num2
fi

read function used to get the input from the user.

-gt stands for greater than.




Output

Enter Num1

100

Enter Num2

200

200


Enter Num1

1

Enter Num2

1000

1000


Topics You Might Like