#!/bin/bash
read -p "请输入第一个数字:" -t 30 num1
read -p "请输入第二个数字:" -t 30 num2
read -p "请输入操作符:" -t 30 ope
if [ -n "$num1" -a -n "$num2" -a -n "$ope" ];then
test1=$( echo $num1|sed 's/[0-9]//g')
test2=$( echo $num2|sed 's/[0-9]//g')
#测试是否是数字
echo "$test1"
#测试是否输入值
echo "$test2"
if [ -z $test1 -a -z $test2];then
echo $test1
echo $num1
if [ $ope == '+' ];then
result=$(($num1+$num2))
echo "$num1+$num2=$result"
elif [ $ope == '-' ];then
result=$(($num1-$num2))
echo "$num1-$num2=$result"
elif [ $ope == '*' ];then
result=$(($num1*$num2))
echo "$num1*$num2=$result"
elif [ $ope == '/' ];then
result=$(($num1/$num2))
echo "$num1/$num2=$result"
fi
fi
else
echo "没有输入字符!"
fi
报错内容为: line 18: [: too many arguments