为了账号安全,请及时绑定邮箱和手机立即绑定

求大神指教,哪里有问题!

  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: 语法错误: 未预期的文件结尾


正在回答

2 回答

还有一个问题,也是第五行,第二个判断条件和第三个判断条件之间少了个 -a

0 回复 有任何疑惑可以回复我~

仔细看第五行,$num2前面少了一个"

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求大神指教,哪里有问题!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信