Floating point results in Bash integer division
Just double-quote ("
) the expression:
echo "$a / ( $b - 34 )" | bc -l
Then bash will expand the $
variables and ignore everything else and bc
will see an expression with parentheses:
$ a=22
$ b=7
$ echo "$a / ( $b - 34 )"
22 / ( 7 - 34 )
$ echo "$a / ( $b - 34 )" | bc -l
-.81481481481481481481
Please note that your echo $(( 22/7 )) | bc -l
actually makes bash calculate 22/7 and then send the result to bc. The integer output is therefore not the result of bc, but simply the input given to bc.
Try echo $(( 22/7 ))
without piping it to bc, and you'll see.