Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a shell script to find the largest number from 3 given
numbers.

Answer Posted / vipul dalwala

if [ $# -ne 3 ]
then
echo "$0: number1 number2 number3 are not given" >&2
exit 1
fi

if [ $1 -eq $2 ] && [ $1 -eq $3 ]
then
echo "All the three numbers are equal"
elif [ $1 -eq $2 ] && [ $1 -gt $3 ]
then
echo "$1 and $2 numbers are equal and are largest
numbers among $1 $2 and $3"
elif [ $1 -eq $3 ] && [ $1 -gt $2 ]
then
echo "$1 and $3 numbers are equal and are largest
numbers among $1 $2 and $3"
elif [ $2 -eq $3 ] && [ $2 -gt $1 ]
then
echo "$2 and $3 numbers are equal and are largest
numbers among $1 $2 and $3"
elif [ $1 -eq $2 ] && [ $1 -lt $3 ]
then
echo "$3 is largest number among $1 $2 and $3"
elif [ $1 -eq $3 ] && [ $1 -lt $2 ]
then
echo "$2 is largest number among $1 $2 and $3"
elif [ $2 -eq $3 ] && [ $2 -lt $1 ]
then
echo "$1 is largest number among $1 $2 and $3"
elif [ $1 -gt $2 ] && [ $1 -gt $3 ]
then
echo "$1 is largest number among $1 $2 and $3"
elif [ $2 -gt $1 ] && [ $2 -gt $3 ]
then
echo "$2 is largest number among $1 $2 and $3"
elif [ $3 -gt $1 ] && [ $3 -gt $2 ]
then
echo "$3 is largest number among $1 $2 and $3"
else
echo "I can not figure out which number is
largest"
fi

Is This Answer Correct ?    22 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I send a mail with a compressed file as an attachment?

980


Is bash an operating system?

931


What is a shell made of?

905


Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

1440


What is ms powershell?

965


How can any user find out all information about a specific user like his default shell, real-life name, default directory, when and how long he has been using the system?

1054


What is shell scripting used for?

933


In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

1069


how to get part of string variable with echo command only?

973


Explain about echo command?

1046


Which scripting language is best for automation?

889


What is the significance of $#?

1017


How to get the 3rd element/column from each line from a file?

1143


How to check if a directory exists?

1100


Explain about login shell?

1054