編寫一個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