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
How do I run a powershell script?
What are the advantages of shell scripting?
Where are cowrie shells found?
write a shell script to check the failed jobs?
What is the first line in every perl script called?
What is the first line in a shell script?
What is echo in shell?
Is bash a shell script?
What is the meaning of $1 in shell script?
What is bash command used for?
What is basename in shell script?
How does path variable work?
one folder contains lot of students name but I want to fetch hello with every student name individually using shell script
What does echo mean in scripting?
What is the purpose of scripting?