I need a bash script that calculates basic tax. It should be callable by
tax.sh or with an optional parameter: tax.sh (capital or help) (interest rate) (duration)
What I have is that:
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
I have no clue how to implement parameters or do the calculation right :/ The calculation is always a little bit smaller then it should be.