I am looking for bash function suitable to do some simple arithmetic expressions on point values For intance
i=1
let "i_mod=${i}+1"; echo $i_mod
gives me 2
but if
i=1.0
let "i_mod=${i}+0.5";echo $i_mod
gives me an error instead of 1.5
or alternatively one of the sollution that has already been suggested in other topic:
i=1.0
echo "$(($i+1.0))"
-bash: 1.0+1.0: syntax error: invalid arithmetic operator (error token is ".0+1.0")
echo "$i + 1.0" | bc
orbc <<< "$i + 1.0"
is enough. You can use scale withbc
also. You can useawk
. etc. In general, the shell is not for arithmetics by its own. – thanasisp Nov 03 '20 at 11:11(( ))
. – thanasisp Nov 03 '20 at 11:22