码迷,mamicode.com
首页 > 系统相关 > 详细

Shell计算器

时间:2017-08-25 12:32:29      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:int   rip   amp   and   name   print   div   ash   sub   

#!/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计算器

标签:int   rip   amp   and   name   print   div   ash   sub   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!