帮忙看看哪错了,一直提示运算符行出错

来源:4-2 shell多分支if语句例:计算器

qq_困_9

2017-07-11 00:10

#!/bin/bash
read -t 30 -p "shu ru shu zi:" num1
read -t 30 -p "shu ru shu zi:" num2
read -t 30 -p "shu ru fu hao:" ope
if [ -n "$num1" -a -n "$num2" -a -n "$ope"  ]
   then
   test1=$( echo $num1 | sed 's/[0-9]//g' )
   test2=$( echo $num1 | sed 's/[0-9]//g' )
   if [ -z "$test1" -a -z "$test2" ]
     then
#!/bin/bash
read -t 30 -p "shu ru shu zi:" num1
read -t 30 -p "shu ru shu zi:" num2
read -t 30 -p "shu ru fu hao:" ope
if [ -n "$num1" -a -n "$num2" -a -n "$ope"  ]
   then
   test1=$( echo $num1 | sed 's/[0-9]//g' )
   test2=$( echo $num1 | sed 's/[0-9]//g' )
   if [ -z "$test1" -a -z "$test2" ]
     then
       if [ "$ope" == '+' ]
         then
             sum=$(($sum1+$sum2))
       elif [ "$ope" == '-' ]
         then
             sum=$(($num1-$num2))

       elif [ "$ope" == '*' ]
        then
             sum=$(( $sum1 * $sum2 ))
       elif [ "$ope" == '/' ]
       then
             sum=$(( $sum1 / $sum2 ))
  else
   echo "shu ru fu hao"
   exit 10
   fi                                                       
   else
   echo "shu ru shu zi"
   exit 11
  fi
  else
  echo "shu ru zi fu"
  fi
  echo "$num1$ope$num2 : $sum"

shu ru shu zi:1
shu ru shu zi:1
shu ru fu hao:+
./if5.sh: line 13: +: syntax error: operand expected (error token is "+")
1+1 :


写回答 关注

1回答

  • qq_藞藞呀_0
    2017-07-11 10:51:14
    已采纳

    提示不已经告诉你了么   应该用"+"  双引号啊

    qq_困_9

    非常感谢!

    2017-07-11 23:18:56

    共 3 条回复 >

shell编程之条件判断与流程控制

Linux shell实用案例学习,一定会使你Linux运维能力再次提高

35507 学习 · 139 问题

查看课程

相似问题