Possible Duplicate:
How to sort an array in BASH
I have numbers in the array 10 30 44 44 69 12 11...
. How to display the highest from array?
echo $NUM //result 69
Possible Duplicate:
How to sort an array in BASH
I have numbers in the array 10 30 44 44 69 12 11...
. How to display the highest from array?
echo $NUM //result 69
You can use sort
to find out.
#! /bin/bash
ar=(10 30 44 44 69 12 11)
IFS=$'\n'
echo "${ar[*]}" | sort -nr | head -n1
Alternatively, search for the maximum yourself:
max=${ar[0]}
for n in "${ar[@]}" ; do
((n > max)) && max=$n
done
echo $max
try this:
a=(10 30 44 44 69 12 11 100)
max=0
for v in ${a[@]}; do
if (( $v > $max )); then max=$v; fi;
done
echo $max
result in 100