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 to get the 3rd element/column from each line from a file?
What are the different types of shell scripting?
What is meant by $1 in shell script?
What is shell geeksforgeeks?
How many fields are present in a crontab file and what does each field specify?
What is the crontab?
What can you do with powershell?
Is shell scripting a programming language?
What is the syntax of while loop in shell scripting?
How do we delete all blank lines in a file?
How do you create a shortcut in linux?
madhar chod unix ke 10 commands dhang se likh nahi sakta hai
Is bash a shell script?
what is tickets $ what low,medium,high priorite pls define time also
What is an inode block?