-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calaulate.sh
65 lines (58 loc) · 1.04 KB
/
Calaulate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#simple calculater
#def by dshowing
num_input() {
while :
do
read -p "first num :" a
expr $a + 0 &> /dev/null
if [ $? -eq 0 ]; then
echo "The first num is : $a"
break
else
echo "$a is not a int var. Try again."
fi
done
while :
do
read -p "second num :" b
expr $b + 0 &> /dev/null
if [ $? -eq 0 ]; then
echo "The second num is : $b"
break
else
echo "$b is not a int var. Try again."
fi
done
}
echo "======================="
echo "| 1.ADD |"
echo "| 2.SUB |"
echo "| 3.MUL |"
echo "| 4.DIV |"
echo "======================="
read -p "Choose your action :" Act
case $Act in
1)
num_input
res=`expr $a + $b`
echo "$a + $b = $res"
;;
2)
num_input
res=`expr $a - $b`
echo "$a + $b = $res"
;;
3)
num_input
res=`expr $a * $b`
echo "$a * $b = $res"
;;
4)
num_input
res=`expr $a / $b`
echo "$a / $b = $res"
;;
*)
echo "Input Error !"
esac