Last Updated: February 25, 2016
·
493
· ochko

Command line calculator

There is bc utility which takes expression similar to C programming language.

Add this function to your ~/.bashrc or ~/.bash_profile:

calc () { echo "$*" | bc -l; }

Then you can use like:

$ calc 2^20 - 256

If you use parenthesis, enclose expression by double quotes:

$ calc "7*(7-6)*6"

Or you can you use bc directly:
$ bc -l <<< "7*7-6*6"