I'm trying to find the max in an array of integers in bash. I'm pretty new to bash. Here is what I have so far...
max="${array[0]}"
for ((i=0;i<${#array[@]};i++))
do
if [ ${array[$i]} > $max ]
then
max="${array[$i]}"
fi
done
where the array is around 500 positive integers ex. 24 27 13 34 2 104 645 411 1042 38 5 24 120 236 2 33 6. Currently it is always returning the last integer in my array. Seems like it should be an easy fix, but I'm not sure what I'm missing. Thanks for any help.