Ever want to use a simple calculator while programming? Mathematica cost too much money? Xcalc look too goofy, and gcalctool too difficult to remember? Well, have I got a simple program for you! As far as I am aware, most major Posix distributions come with a command-line calculator called “BC.” It’s great for simple number crunching and can deal with n-digit floating point operations. It’s similar to mathematica, matlab, etc. in that it can store temporary variables, write functions, and work with arrays. Reading through the man page again, bc’s actually a simplified version of C, allowing for loops, comments, and so on. Of course, I’ve never used it to these capacities, but maybe you will find it more interesting! So far, I know that bc comes standard with Debian, Ubuntu, and FreeBsd.
$ bc – run bc from terminal
3+1 – type in an expression
> 4 – get your answer
4.3333 – 2.22 – I have noticed that decimal operations do not work if we are dividing
(55 % 9) – 3 – The percent sign is the operator for “modular,” which, more or less means “give the remainder”
x=46; x+2 – As described before, you can define variables. Also, as with bash, a colon separates statements.