#!/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个数,判断最大值,最小值,总和
最新推荐文章于 2022-11-26 21:34:52 发布
本文介绍了一个简单的Bash脚本,该脚本能接收用户输入的多个数值,并计算这些数值的最大值、最小值及总和。通过使用循环和条件判断,脚本能够确保输入的有效性并正确进行数值处理。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
ComfyUI
AI应用
ComfyUI
ComfyUI是一款易于上手的工作流设计工具,具有以下特点:基于工作流节点设计,可视化工作流搭建,快速切换工作流,对显存占用小,速度快,支持多种插件,如ADetailer、Controlnet和AnimateDIFF等
1万+

被折叠的 条评论
为什么被折叠?



