Thursday, August 29, 2013

Floating point calculation in linux shell script

BC is a useful utility/language to do floating point calculation in linux shell script.

it has so many formats, here are two examples,
bc <<< 20+5/2
bc <<< 'scale=4;20+5/2'
 
here scale=4 means we will consider decimal up to four digits.

another example may be,
 
echo "scale=4;$a/$b" | bc
 
details here.
 
  
-->

No comments: