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


 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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM