Shell计算器

#!/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))

posted @ 2017-08-25 11:16  盛碗米饭  阅读(653)  评论(0编辑  收藏  举报