输入5个数,计算和,最大值与最小值
#!/bin /bash
i=0
read -p "x$(($i+1)):" max
i=$(($i+1))
min=$max
sum=$max
while [ $i -lt 5 ]
do
read -p "x$(($i+1)):" x
if [ $x -gt $max ]
then
max=$x
fi
if [ $x -lt $min ]
then
min=$x
fi
sum=$(($sum+$x))
i=$(($i+1))
done
echo "sum=$sum max=$max min=$min"
运行结果
x1:1
x2:2
x3:3
x4:8
x5:1
sum=15 max=8 min=1