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

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

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.