Minimum and maximum

Basic types / Numbers / Mathematical operations

#bash has no min and max; for whole numbers
#the ternary operator of $(( )) does the job
a=2
b=1
minValue=$((a < b ? a : b))
#minValue is 1

#the maximum of an array: a loop
lst=(2 1 3)
maxValue=${lst[0]}
for x in "${lst[@]}"; do
    maxValue=$((x > maxValue ? x : maxValue))
done
#maxValue is 3

#fractions: sort -n orders the numbers, head and tail take the ends
minDouble=$(printf '%s\n' 2.5 1.5 | sort -n | head -n 1)
#minDouble is 1.5
maxDouble=$(printf '%s\n' 2.5 1.5 | sort -n | tail -n 1)
#maxDouble is 2.5

echo "minValue is $minValue"
echo "maxValue is $maxValue"
echo "minDouble is $minDouble"
echo "maxDouble is $maxDouble"