The bc Command
The bc command is an arithmetic utility not limited to integers:
$ bc scale=4 8/3 2.6666 2.5 * 4.1/6.9 1.4855 quit $
In this example, you invoke bc and set scale to 4, meaning that you want it to calculate any fraction to four decimal places. You ask it to calculate 8/3, which gives 2.6666 and then a more complex calculation. Note that spaces are optional. Finally you enter quit to return to the shell prompt. bc can handle addition (+), subtraction (-), multiplication (*), division (/), remainder or modulo (%), and integer exponentiation (^). It can accurately compute numbers of any size
9238472938742937 * 29384729347298472 271470026887302339647844620892264
and can be used in shell variable assignment to assign calculated values ...
Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.