1 #!/bin/bash
2 #FUNCTION Calculator
3 #AUTHOR Wangbo
4 #DATE 2015-09-26
5
6
7 function Checknum ()
8 {
9 Expr + 0 &>/dev/null
10
Case $? Inch
12 0)
return $
14;;
15 *)
16
Read-t 50-p "Please input integer:" int
18
Check "$int"
20
Return "$int"
22
23;;
Esac
25}
26
function operate ()
28 {
echo "$"
If ["$" = = "+"]
Then
echo "$ (($1$2$3))"
-Fi
If ["$" = "-"]
Then
echo "$ (($1$2$3))"
Panax Notoginseng fi
If ["$" = "*"]
About
echo "DDD"
echo "$ (($1$2$3))"
Fi
If ["$" = = "/"]
Then
echo "$ (($1$2$3))"
-Fi
47}
48
#get first number from user
Read-t 50-p "Please input first number:" First
51
Checknum "$first"
53
#get First Number
Fnum=$?
56
Operate #get
Read-t 50-p "Please input first operate (+-*/):" Operate
59
#get second number from user
Read-t 50-p "Please input second number:" Second
62
Checknum "$second"
64
#get Second Number
Snum=$?
67
#print result
69
Operate $fnum $operate $snum
This article is from the Shell Implementation Calculator blog, so be sure to keep this source http://codekong.blog.51cto.com/10704076/1699616
Shell-Implemented Calculators