加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

如何用shell编写一个简单的计算器?

(2010-11-28 01:46:29)
标签:

shell

shell写计算器

it

分类: 技术文档

今天是周日,半夜还在玩弄因为刚学shell所以就写了个简单计算机玩玩大家不要笑话偶,之前shell一点都不会

总监让我周日把服务器内核的优化参数写个文档,没有思路啊就惆怅的了,先学学shell放松下吧。

#vi numb.sh

#chmod +x numb.sh

#cat numb.sh

#!/bin/bash
echo "先选择运算的种类 加减乘除,然后分别输入运费的数字就可以得到结果,输入时间为30秒"
 read -p "Please enter the type of operation + or - or * or / :" -t 30 f
 case "$f" in
 "+")
 read -p "Please enter the number1:" -t 30 numb1

 read -p "Please enter the number2:" -t 30 numb2
typeset -i numb3="$numb1+$numb2"
echo $numb3
 ;;
 "*")
 read -p "Please enter the number1:" -t 30 numb1
 read -p "Please enter the number2:" -t 30 numb2
 typeset -i numb3="$numb1*$numb2"
echo $numb3
;;
"-")
 read -p "Please enter the number1:" -t 30 numb1
 read -p "Please enter the number2:" -t 30 numb2
 typeset -i numb3="$numb1-$numb2"
echo $numb3
;;
"/")
 read -p "Please enter the number1:" -t 30 numb1
 read -p "Please enter the number2:" -t 30 numb2
 typeset -i numb3="$numb1/$numb2"
echo $numb3
;;
*)
echo "error,Please re-run!"
esac

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有