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

write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?

4079


What is shell scripting?

1001


What are the different commands available to check the disk usage?

952


Is shell scripting useful?

1011


How do I debug a shell script?

1041


Is scripting and coding the same thing?

952


one folder contains lot of students name but I want to fetch hello with every student name individually using shell script

924


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?

1072


What are the different types of commonly used shells on a typical linux system?

1034


How to check if the previous command was run successfully?

1004


What is the fastest scripting language?

958


I have 2 files and I want to print the records which are common to both.

1128


How will you connect to a database server from linux?

1001


How to calculate the number of passed arguments?

1026


How will you copy a file from one machine to other?

964