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 can I set the default rwx permission to all users on every file which is created in the current shell?
Given a file find the count of lines containing the word "abc".
Explain about debugging?
What is console line?
What is shell environment?
How will you emulate wc –l using awk?
What is basename in shell script?
Is shell a part of kernel?
Is powershell a language?
What are "c" and "b" permission fields of a file?
How to get the last line from a file using just the terminal?
Explain about login shell?
What does echo mean in scripting?
What is a shell script in windows?
How can the contents of a file inside jar be read without extracting in a shell script?