首页 > 系统服务 > 详细

Shell计算器

时间:2017-08-25 12:00:49      阅读:278      评论:0      收藏:0      [点我收藏+]

#!/bin/bash
# filename : jisuan.sh
# description : add, subtract, multiply, and divide
print_usage(){
echo -e "USAGE:$0 NUM1 {+|-|*|%} NUM2"
exit 1
}
if [ $# -ne 3 ];then
print_usage
fi

firstnum=$1
secondnum=$3
op=$2

if [ -n "$(echo $firstnum|sed ‘s/[0-9]//g‘)" ];then
print_usage
fi

if [ "$op" != "+" ]&&[ "$op!="-"" ]&&[ "$op" != "*" ]&&[ "$op" != "/" ];then
print_usage
fi

if [ -n "$(echo $secondnum|sed ‘s/[0-9]//g‘)" ];then
print_usage
fi

echo "${firstnum}${op}${secondnum}=$((${firstnum}${op}${secondnum}))"

另;echo $(($1))

Shell计算器

原文:http://www.cnblogs.com/shengy/p/7427105.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!