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))"
#!/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))"
相关文章推荐
- Powershell 自动化安装zabbix agent
- 解决删除大量文件的问题 -bash: /usr/bin/sudo: Argument list too long
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)()【转】
- 使用Bash Shell处理JSON文件
- 40 个很有用的 Mac OS X Shell 脚本和终端命令
- 解决Xshell显示中文乱码的问题
- Bash 快捷键大全
- Bash中一些重要的命令
- Shell脚本实现判断IP地址是否在一个ip段内代码分享
- php-fpm开机自动启动Shell脚本
- 整理的Linux Shell语法速查表(用C语言语法来作对比)
- 70个经典的 Shell 脚本面试问题
- -bash: zip: command not found提示解决办法
- 感叹号:bash 的历史扩展功能
- bash字符串处理
- Linux Shell 学习笔记(三)--Shell变量
- Linux Shell 学习笔记(二)
- Linux Shell 学习笔记(一)
- php-fpm开机自动启动Shell脚本
- Shell脚本实现判断IP地址是否在一个ip段内代码分享