Wednesday, October 24, 2007

Simple But Useful: Finding the Highest Number

Hey There,

This is something you do every day, probably. Compare things. And then, based on whatever your objective is, you ferret out the one object that meets your requirements.

This is a really simple script, assuming input on the command line of any number of numbers, separated by spaces. When it's done, it will print out the largest number of the bunch.

Not super exciting, but fundamental and applicable to lots of things, depending on what you want to compare. Later on, I'll post the equivalent alpha version of this numeric scriptlet


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/bin/ksh

#
# 2007 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

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


Yes, today is my day of rest ;)

,Mike