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