求大神指教,哪里有問題!
? 1 #!/bin/bash
? ? ? 2? read -p "請輸入一個數字:" num1
? ? ? 3? read -p "請輸入運算符:" ope
? ? ? 4? read -p "請輸入第二個數:" num2
? ? ? 5 if [ -n "$num1" -a -n $num2" -n "$ope" ]
? ? ? 6? ?then
? ? ? 1 #!/bin/bash
? ? ? 2? read -p "請輸入一個數字:" num1
? ? ? 3? read -p "請輸入運算符:" ope
? ? ? 4? read -p "請輸入第二個數:" num2
? ? ? 5 if [ -n "$num1" -a -n $num2" -n "$ope" ]
? ? ? 6? ?then
? ? ? 7? ? ? test1=$(echo $num1 | sed 's/[0-9]//g')
? ? ? 8? ? ? test2=$(echo $num2 | sed 's/[0-9]//g')
? ? ? 9? ?if [ -z "$test1" -a -z "$test2" ]
? ? ?10? ? ?then
? ? ?11? ? ? if [ "$ope" == "+" ]
? ? ?12? ? ? then
? ? ?13? ? ?sum=$(($num1+$num2))
? ? ?14? ?elif? [ "$ope" == "-" ]
? ? ?15? ? ? then
? ? ?16? ? sum=$(($num1-$num2))
? ? ?17? ?elif [ "$ope" == "*" ]
? ? ?18? ? then
? ? ?19? ? ? sum=$(($num1*$num2))
? ? ?20? elif [ "$ope" == "/" ]
? ? ?21? ? then
? ? ?22? ? ? ?sum=$(($num/$num2))
? ? ?23? else
? ? ?24? ? echo "請輸入正確運算符"
? ? ?25? ? exit 1
? ? ?26 fi
? ? ?27? ?else
? ? ?28? ? echo "請輸入數字類型"
? ? ?29? ?exit 2
? ? ?30 fi
? ? ?31? ?else
? ? ?32? ?echo "輸入不能不為空"
? ? ?33? exit 3
? ? ?34 fi
? ? ?35? echo "$num1 $ope $num2 :$sum"
報錯信息:
./sum.sh:行35: 尋找匹配的 `"' 是遇到了未預期的文件結束符
./sum.sh:行37: 語法錯誤: 未預期的文件結尾
2018-09-24
還有一個問題,也是第五行,第二個判斷條件和第三個判斷條件之間少了個 -a
2018-09-24
仔細看第五行,$num2前面少了一個"