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
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
What is shell scripting?
What are the different commands available to check the disk usage?
Is shell scripting useful?
How do I debug a shell script?
Is scripting and coding the same thing?
one folder contains lot of students name but I want to fetch hello with every student name individually using shell script
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 are the different types of commonly used shells on a typical linux system?
How to check if the previous command was run successfully?
What is the fastest scripting language?
I have 2 files and I want to print the records which are common to both.
How will you connect to a database server from linux?
How to calculate the number of passed arguments?
How will you copy a file from one machine to other?