编写一个shell,输入任意三个整数,判断最大数。

时间:2021-04-28 19:09:21   收藏:0   阅读:29
 1 #!/bin/bash
 2 echo "Enter 3 numbers,please"
 3 read -r -p "input the first number: " n1
 4 read -r -p "input the second number: " n2
 5 read -r -p "input the third number: " n3
 6 MAX=$n1
 7 if [ "$n2" -ge "$n1" ]; then
 8     MAX=$n2
 9 fi
10 if [ "$n3" -ge "$MAX" ]; then
11     MAX=$n3
12 fi
13 echo "The max number is $MAX"

比较简单,注意 [ 两边加 空格。

命令 read  -r    意思是  do not allow backslashes "\" to escape any characters.

 

参照原文:https://blog.csdn.net/muyanmoyang/article/details/48136945

 

原文:https://www.cnblogs.com/tm2002/p/14714842.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!