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
How can I send a mail with a compressed file as an attachment?
Is bash an operating system?
What is a shell made of?
Write a command sequence to find all the files modified in less than 2 days and print the record count of each.
What is ms powershell?
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?
What is shell scripting used for?
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?
how to get part of string variable with echo command only?
Explain about echo command?
Which scripting language is best for automation?
What is the significance of $#?
How to get the 3rd element/column from each line from a file?
How to check if a directory exists?
Explain about login shell?