just_say_东东
2015-10-17 22:22
#!/bin/bash
read -t 30 -p "Please input number1:" number1
read -t 30 -p "Please input number2:" number2
read -t 30 -p "Please input a operator:" operator
if [ -n "$number1" -a -n "$number2" -a -n "$operator" ]
then
test1=$(echo $number1 | sed's/[0-9]//g' )
test2=$(echo $number2 | sed's/[0-9]//g' )
if [ -z "$test1" -a -z "$test2" ]
then
if [ "$operator" == '+' ]
then
result=$(($number1 + $number2))
elif [ "$operator" == '-' ]
then
result=$(($number1 - $number2))
elif [ "$operator" == '*' ]
then
result=$(($number1 * $number2))
elif [ "$operator" == '/' ]
then
result=$(($number1 / $number2))
else
echo "Please Enter a vaild sybul"
exit 10
fi
else
echo "Please Enter a number"
exit 11
fi
else
echo "Please Enter vaild number"
exit 12
fi
echo "$number1 $operator $number2:$resulte"
~
~
test1 和 test2 那两句中,sed 和 后面的引号之间好像没有空格: sed 's/[0-9]//g'
最后输出结果时,result 错打成 resulte了。
这是怎么回事
shell编程之条件判断与流程控制
35507 学习 · 139 问题
相似问题