gao634209276
2016-02-05 15:26
#!/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
挺好的,但是运算符同时输入+-×/应该也会运行吧
写的不错哦.
shell编程之条件判断与流程控制
35507 学习 · 139 问题
相似问题