1 #!/bin/bash
2 #FUNCTION calculator
3 #AUTHOR wangbo
4 #DATE 2015-09-26
5
6
7 function checknum()
8 {
9 expr $1 + 0 &>/dev/null
10
11 case $? in
12 0)
13 return $1
14 ;;
15 *)
16
17 read -t 50 -p "please input integer:" int
18
19 check "$int"
20
21 return "$int"
22
23 ;;
24 esac
25 }
26
27 function operate()
28 {
29 echo "$2"
30 if [ "$2" == "+" ]
31 then
32 echo "$(($1$2$3))"
33 fi
34 if [ "$2" == "-" ]
35 then
36 echo "$(($1$2$3))"
37 fi
38 if [ "$2" == "*" ]
39 then
40 echo "ddd"
41 echo "$(($1$2$3))"
42 fi
43 if [ "$2" == "/" ]
44 then
45 echo "$(($1$2$3))"
46 fi
47 }
48
49 #get first number from user
50 read -t 50 -p "please input first number:" first
51
52 checknum "$first"
53
54 #get first number
55 fnum=$?
56
57 #get operate
58 read -t 50 -p "please input first operate(+ - * /):" operate
59
60 #get second number from user
61 read -t 50 -p "please input second number:" second
62
63 checknum "$second"
64
65 #get second number
66 snum=$?
67
68 #print result
69
70 operate $fnum $operate $snum