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))

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