#!/bin/bash
##任意输入n个数,判断最大值,最小值,总和
sum=0
n=0
read -p "please input the count of number:" count
#max=0
#min=0
for i in `seq $count`
do
read -p "please input the $i number:" temp
((temp+0)) 1>/dev/null 2>&1
if (($? == 0 ))
then
echo "$temp is a number"
else
echo "$temp is not a number,please input again"
continue
fi
sum=$((sum+temp))
[ $n -eq 0 ] && max=${temp} && min=${temp}
n=$((n+1))
if ((max < temp))
then
max=${temp}
fi
if ((min > temp))
then
min=${temp}
fi
done
echo "sum=$sum, max=$max, min=$min"
shell脚本之任意输入n个数,判断最大值,最小值,总和
最新推荐文章于 2024-08-06 10:36:58 发布