Bc

From Notes_Wiki
Revision as of 11:01, 14 November 2012 by Saurabh (talk | contribs) (Created page with "=bc= '<tt>bc</tt>' is an arbitary precision calculator for Linux. It is very useful as normal shell arithmetic is very limited. For example shell does not supports division o...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

bc

'bc' is an arbitary precision calculator for Linux. It is very useful as normal shell arithmetic is very limited. For example shell does not supports division of real numbers.


Using bc to perform divison of real numbers in shell script

Example script which uses 'bc' to divide two numbers is:

#!/bin/bash

Numerator=5
Denominator=2

Quotient=$(bc <<END
scale=20
$Numerator/$Denominator
quit
END
)

echo "Result is $Quotient"

exit 0