Difference between revisions of "Bc"

From Notes_Wiki
m
m
Line 1: Line 1:
<yambe:breadcrumb>Shell scripting</yambe:breadcrumb>
<yambe:breadcrumb self="Bc">Shell scripting|Shell scripting</yambe:breadcrumb>
=bc=
=bc=


Line 25: Line 25:
exit 0
exit 0
</pre>
</pre>
<yambe:breadcrumb self="Bc">Shell scripting|Shell scripting</yambe:breadcrumb>

Revision as of 05:41, 18 September 2018

<yambe:breadcrumb self="Bc">Shell scripting|Shell scripting</yambe:breadcrumb>

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


<yambe:breadcrumb self="Bc">Shell scripting|Shell scripting</yambe:breadcrumb>