1 #!/bin/bash
2
3 ##计算器脚本
4
5 read -p "Please input a number:" num1
6 read -p "Please input a yunsuanfu:" ope
7 read -p "PLease input another number:" num2
8 ##先输入运算符和要运算的数字
9
10 if [ !-z "$num1" -a !-z "$num2" -a -z "$ope" ]
11 then
12 ##判断是否有输入数字和运算符
13 test1=$(echo $num1 | sed 's/[0-9]//g')
14 test2=$(echo $num2 | sed 's/[0-9]//g')
15 ##判断输入的num1和num2是否为数字,运算符是否正确
16 if [-z "$test1" -a -z "$test2" -a -z "$ope" ]
17 then
18 if ["$ope"=="+"];then
19 sum=$(( $num1 + $num2 ))
20 elif ["$ope"=="-"];then
21 sum=$(( $num1 - $num2 ))
22 elif ["$ope"=="*"];then
23 sum=$(( $num1 * $num2 ))
24 elif ["$ope"=="/"];then
25 sum=$(( $num1 / $num2 ))
26 else
27 echo "please input a true ope"
28 exit 10
29 #判断是否是正确的运算符
30 fi
31 else
32 echo "Please input a true num"
33 exit 11
34 fi
35 else
36 echo "qing shu ru nei rong"
37 exit 12
38 fi
39
40 echo "$num1 $ope $num2 = $sum"
test.sh: line 10: [: too many arguments
qing shu ru nei rong