Find Smallest of 3 Numbers

Write a shell script to find the smallest of three numbers that are read from the keyboard.

Questions by pankajforall2003

Showing Answers 1 - 6 of 6 Answers

goksn

  • Sep 7th, 2009
 

echo first_num
read first_num
echo second_num
read second_num
echo third_num
read third_num

if (first_num>second_num) then
if (first_num>third_num) then
echo $first_num is the biggest
else
echo $third_num is the biggest
elif
(second_num>third_num) then
echo $second_num is the biggest
else
echo$third_num is the biggest

or else we can use sort command

sort -r


  Was this answer useful?  Yes

#@goskn You have given for the biggest number :) ..
# here is the code for the lowest number
first=90;
second=3;
third=45;
echo " $first $second $third ";
if [ $first -gt $second ]
then
echo " ";
if [ $third -gt $second ]
then
echo Second is smallest;
else
echo Third is smallest ;
fi
elif [ $second -gt $third ]
then
echo third is smallest;
else
echo first is smallest;
fi

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions