954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Echoing the highest of ten inputed numbers.

OK Hi peeps new to daniweb. I have a script missing for one of my classes because I missed due to work :( It's a very simple4 script (I think) It need to eccept the input of ten numbers compair them and output the highest number. This simpler the better here folks. Please Help. *Pulling Hair out!* :S

dewey_witt
Newbie Poster
1 post since Aug 2007
Reputation Points: 10
Solved Threads: 0
 
OK Hi peeps new to daniweb. I have a script missing for one of my classes because I missed due to work :( It's a very simple4 script (I think) It need to eccept the input of ten numbers compair them and output the highest number. This simpler the better here folks. Please Help. *Pulling Hair out!* :S

try cat "filename" | sort | uniq

iwalker147
Newbie Poster
2 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Hey There,

Assuming you're getting the variables from the command line

Ex: script 1 4 38 4 7 ...

#!/bin/ksh

highest_number=0
for x in $@
do
if [ $x -gt $highest_number ]
then
highest_number=$x
fi
done
print "Highest Number is $highest_number"

Hope this helps :)

, Mike

eggi
Posting Pro in Training
400 posts since Oct 2007
Reputation Points: 102
Solved Threads: 47
 

With zsh:

% set -- 03 32 156 4 593 2 033 490 5 12
% print ${${(n)@}[-1]}                 
593


with sort:

$ numbers="03 32 156 4 593 2 033 490 5 12"
$ set -- $(printf "%d\n" $numbers|sort -nr)
$ printf "%d\n" "$1"
593
radoulov
Junior Poster in Training
54 posts since Feb 2007
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You