#!/bin/bash
read -t 30 -p "num2:" num2
read -t 30 -p "operator:" 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')
if [ -z "$test1" -a -z "$test2" ]
then
if [ $ope=='+' -o $ope=='-' -o $ope=='*' -o $ope=='/' ]
then
res=$((num1 $ope num2))
else
echo "no operator"
exit 10
fi
else
echo "no numbers"
exit 11
fi
else
echo "no values"
exit 12
fi
挺好的,但是运算符同时输入+-×/应该也会运行吧
写的不错哦.