2 回答
TA贡献9条经验 获得超1个赞
#!/bin/bash
read -t 30 -p "please input number:" number1
read -t 30 -p "please input number:" number2
read -t 30 -p "please input fuhao" number3
if [ -n "$number1" -a -n "$number2" -a -n "$number3" ]
then
test1=$(echo $number1 | sed 's/[0-9]//g')
test2=$(echo $number2 | sed 's/[0-9]//g')
test3=$(echo "$number3" | sed 's/[\+\-\*\/]//g')
if [ -z "$test1" -a -z "$test2" -a -z "$test3" ]
then
case "$number3" in
'+')
echo $(( $number1 + $number2 ))
;;
'*')
echo $(( $number1 * $number2 ))
;;
'-')
echo $(( $number1 - $number2 ))
;;
'/')
echo $(( $number1 / $number2 ))
;;
esac
fi
fi
刚才那个有bug,看这个
TA贡献9条经验 获得超1个赞
#!/bin/bash read -t 30 -p "please input number:" number1 read -t 30 -p "please input number:" number2 read -t 30 -p "please input fuhao" number3 if [ -n "$number1" -a -n "$number2" -a -n "$number3" ] then test1=$(echo $number1 | sed 's/[0-9]//g') test2=$(echo $number2 | sed 's/[0-9]//g') test3=$(echo $number3 | sed 's/[\+\-\*\/]//g') if [ -z "$test1" -a -z "$test2" -a -z "$test3" ] then case "$number3" in '+') echo $(( $number1 + $number2 )) ;; '*') echo $(( $number1 * $number2 )) ;; '-') echo $(( $number1 - $number2 )) ;; '/') echo $(( $number1 / $number2 )) ;; esac fi fi
- 2 回答
- 0 关注
- 1435 浏览
添加回答
举报