shell 从输入的参数里找出最大值,最小值,平均值

时间:2022-09-15 15:11:39
max=$1
min=$2
sum=0
for i in $@
do
    if [ $max -lt $i ];then
    max=$i
    fi
    if [ $min -gt $i ];then
    min=$i
    fi
    let sum+=i
done
    echo "max:$max"
    echo "min:$min"
    echo -n "average:"
    echo "scale=2; $sum/$#" | bc