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

Answer Posted / aseem

Hi

"In continuation to above answer.

If you want to write a script in more generic way.

if [ $# -eq 0 ]
then
echo "$0: numbers are not given" >&2
exit 1
fi
LARGEST=$(echo $* | xargs -n1 | sort -nr | tail -1)
echo "$LARGEST is largest number""

The above script is good but there is a small msitake. As
numeric sort is used in reverse order so the biggest number
will come first, so we should use head -1 rather than tail -
1

Is This Answer Correct ?    9 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I run a powershell script?

784


What are the advantages of shell scripting?

816


Where are cowrie shells found?

761


write a shell script to check the failed jobs?

4142


What is the first line in every perl script called?

788


What is the first line in a shell script?

777


What is echo in shell?

857


Is bash a shell script?

811


What is the meaning of $1 in shell script?

823


What is bash command used for?

772


What is basename in shell script?

795


How does path variable work?

717


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

735


What does echo mean in scripting?

780


What is the purpose of scripting?

740