shell脚本之任意输入n个数,判断最大值,最小值,总和

匿名 (未验证) 提交于 2019-12-03 00:21:02
#!/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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!