Random Wisdom

Tag: bc

BASH as a simple calculator

by on Sep.25, 2006, under How To ..., Linux, Software

As long as you are satisfied with integer results:

[darkknight@darkworld ~]$ echo $[32 * 98]
3136
[darkknight@darkworld ~]$ echo $[332 / 98]
3
[darkknight@darkworld ~]$ echo $[29 + 56]
85
[darkknight@darkworld ~]$ echo $[29 - 156]
-127

For full precision, one can use bc:

$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
332/98
3.38775510204081632653
7 Comments :, , more...