I am trying to write a simple multiplication between int and float numbers in bash:
int='10'
float='0.001'
# should give 0.01
multip=$(( float*int ))
produces error
bash: 0.001 : erreur de syntaxe : opérateur arithmétique non valable (le symbole erroné est « .001 »)
what should be fixed ?
>Solution :
Bash doesn’t support floats. Use an external program for that, e.g. bc.
int=10
float=0.001
multip=$(bc <<< "$int * $float")
Note that bc doesn’t output the leading 0 in 0.01, so you need to add some string processing, e.g.
multip=${multip/#./0.} # Insert 0 before the leading dot.