用shell编程,输入任意几个数,然后输出最大数?

 我来答
lj84386655
2012-10-23 · TA获得超过945个赞
知道小有建树答主
回答量:358
采纳率:100%
帮助的人:251万
展开全部
[root@liuxiting testdir]# cat maxMumber.sh
#!/bin/bash
read -p "input num : " num
if [ $num -eq 0 ]
then
echo no number to compare!
elif [ $num -eq 1 ]
then
read res
elif [ $num -eq 2 ]
then
read a
read b
if [ $a -gt $b ]
then
res=$a
else
res=$b
fi
else
read res
for (( i=1; i< $num ; i++ ));
do
read a
if [ $a -gt $res ]
then
res=$a;
fi
done
fi
echo max number is $res

使用方法:先输入总个数,在依次输出要比较的数,如:
[root@liuxiting testdir]# ./maxMumber.sh
input num : 4
2
3
41
23
max number is 41
[root@liuxiting testdir]#
清河大侠
2012-10-23 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.6万
采纳率:81%
帮助的人:1243万
展开全部
弄个简单的管道组合,看能否帮助你:
$ cat | sort -n | tail -1
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式