您的位置:首页 > 运维架构 > Shell

shell脚本生成一个简单的计算器

2015-06-19 16:31 501 查看
[root@nginx scripts]# cat calculator.sh

#!/bin/bash

#DATE:2015-6-19

#Author:devon

#Functions: a calculator for integer operators "+,-,*,/,%,** "

usage1() {

echo -n "sorry,you have input a wrong number,please input a right number:"

}

usage2() {

echo -n "sorry,you have input a wrong operator,please input a right operator:"

}

read -p"Please input first integer:" a

while [ $a != `echo $a/1|bc` ];do

usage1

read a

done

read -p"please input a operator:" b

case $b in

"+"|"-"|"*"|"/"|"%"|"**")

x=0;;

*)

#echo -n "please input a right operator:"

#read b

x=1;;

esac

while [ $x -eq 1 ];do

usage2

read b

case $b in

"+"|"-"|"*"|"/"|"%"|"**")

x=0;;

*)

x=1;;

esac

done

read -p"Please input last integer:" c

while [ $c != `echo $c/1|bc` ];do

usage1

read c

done

echo "$a$b$c = $(($a$b$c))"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: