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

[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))"

你可能感兴趣的:(shell)