#!/bin/bash
#
if [ $# -lt 3 ];then
echo "para err."
exit 1
fi
if [ "$2" == "/" ];then
result=`echo "scale=2;$1/$3;" | bc`
echo $result
elif [ "$2" == "+" ];then
result=`echo "scale=2;$1+$3;" | bc`
echo $result
elif [ "$2" == "-" ];then
result=`bc <<< "scale=2;$1-$3;"`
echo $result
elif [ "$2" == "*" ];then
result=`echo "scale=2;$1*$3;" | bc`
echo $result
else
echo "opt err."
fi
备份地址: 【实现shell四则运算】