bc: using "scale" with bash variable [closed]
Replace single quotes with double; because with single quotes $A
in your equation is not expanded, rather considered as literally $A
not 12
A=12 ; bc <<< "scale=2;$(($A/5))"
2
Also, inside $(()) to variable does not need to be specified as $A
, just A
will do, e.g.
A=12 ; bc <<< "scale=2;$((A/5))"
2
Next, when doing $(()) you invoke subshell, which is not what you want to do because bc
does not do anything then. Try this
A=12 ; bc <<< "scale=2; $A/5"
2.40
Try with:
A=12;echo 'scale=2;'"$A / 5"|bc -l