shell腳本:
!/bin/bash
eam1(){
read -p "pl input ur num1:" num1
read -p "pl input ur num2:" num2
}shell
eam1bash
result1=expr $num1 + 0
result2=expr $num2 + 0
ide
if [[ $result1 != $num1 ]];then
echo "pl re-input num"
eam1
elif [[ $result2 != $num2 ]];then
echo "pl re-input num"
eam1
ficode
if [ $num1 -eq $num2 ];then
echo "num1=num2"
elif [ $num1 -gt $num2 ];then
echo "num1>num2"
else
echo "num1<num2"
fiinput
注意:
elif [[ $result2 != $num2 ]] 這個地方必須用兩個 [ ,由於,代碼中判斷,若是輸入的不是兩個整數就須要從新輸入,像eq ne gt等等只能比較整數,因此我採用了 !=的方式,但他必須用在雙()或者雙[]中。it