Минимальное и максимальное значения

Массивы и коллекции / Массивы

numbers=(11 2 5 7 3)

#bash has no min and max: one pass finds both
minValue=${numbers[0]}
maxValue=${numbers[0]}
for number in "${numbers[@]}"; do
    if ((number < minValue)); then
        minValue=$number
    fi
    if ((number > maxValue)); then
        maxValue=$number
    fi
done
#minValue is 2
#maxValue is 11

#sort -n: the first line is the smallest, the last one is the largest
fromSort=$(printf '%s\n' "${numbers[@]}" | sort -n | head -n 1)
#fromSort is 2

#(( )) compares numbers, but < inside [[ ]] compares text
[[ 11 < 2 ]] && textLess=true || textLess=false
#textLess is true: "1" goes before "2"

echo "minValue is $minValue"
echo "maxValue is $maxValue"
echo "fromSort is $fromSort"
echo "textLess is $textLess"