BASH as a simple calculator
by Mostafa 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
October 14th, 2011 on 6:16 am
oh hey thanks. 🙂
December 3rd, 2011 on 7:08 pm
Thanks!!
April 19th, 2012 on 4:04 pm
Rob
June 5th, 2012 on 11:16 pm
Simple and useful, thanx 🙂
July 31st, 2012 on 11:09 am
I’ve added this to my .bashrc: calc() { echo $@ | bc; }
February 24th, 2014 on 8:34 am
Most excellent, simple and easy now 😀
May 1st, 2014 on 3:26 pm
this works too
$ echo $((13*13))
169