我需要一个计算基本税的 bash 脚本。它应该可以通过
tax.sh 或带有可选参数:tax.sh(资本或帮助)(利率)(持续时间)
我所拥有的是:
re='^-?[0-9]+([.][0-9]+)?$'
echo "capital: "
read capital
if ![[ $capital =~ $re ]] ; then
echo "invalid capital!" >&2; exit 1
fi
echo "rate: "
read rate
if ![[ $rate=~ $re ]] ; then
echo "invalid rate!" >&2; exit 1
fi
echo "duration: "
read duration
if ![[ $duration=~ $re ]] ; then
echo "invalid duration!" >&2; exit 1
fi
echo "the capital after "$duration" years is: "
echo "scale=5;($capital*($rate/100)*$duration)+$capital" | bc
我不知道如何实现参数或正确计算:/计算总是比它应该的小一点。