#!/bin/bash
read -t 30 -p "please input num1: " num1
read -t 30 -p "please input num2: " num2
read -t 30 -p "please input operator: " op
if [ -n "$num1" -a -n "$num2" -a -n "$op" ]
then
test1=$(echo $num1 | sed 's/[0-9]//g')
test2=$(echo $num2 | sed 's/[0-9]//g')
if [ -z "$test1" -a -z "$test2" ]
then
if[ "$op" == '+' ]
then
res=$(($num1+$num2))
elif[ "$op" == '-' ]
then
res=$(($num1-$num2))
elif[ "$op" == '*' ]
then
res=$(($num1*$num2))
elif[ "$op" == '/' ]
then
res=$(($num1/$num2))
else
echo "yunsuanfu shuru cuowu !!!"
exit 10
fi
else
echo "shuru shuzi cuowu!!!"
exit 11
fi
else
echo "qing shuru neirong"
exit 12
fi
echo " $num1$op$num2=$res "
13行 if 和 [ 之间要有空格,
16 19 22 行 elif 和 [ 之间要有空格,
改完即可.