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
Is shell scripting a language?
How to print all the arguments provided to the script?
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
Why do we use shell scripting?
What are the four fundamental components of every file system on linux?
How can I send a mail with a compressed file as an attachment?
Write down the syntax of "for " loop
What is path in shell script?
What is a shell script in windows?
What is a beat in a script?
What exactly is a shell?
c program the catches the ctrl-c(SIGINT) Signal for the first time and prints a output rather and exit on pressing Ctrl-C again
What is sudo command?
Which scripting language is best for automation?
What are the 3 standard streams in linux?