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

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by radoulov
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

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

0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.