Tags
arithmetic, bash, bc, calculator, cli
Add the following function to the ~/.bashrc or ~/.bash_aliases, source the former and you’ll get a better command line calculator:
? () { echo "$*" | bc -l; }
You can use it the following way:
$ ? 7*3-5.5
and, no doubt that you’ll get 15.5 as the answer.
N.B. If you use parentheses, you must enclose the whole expression by double quotes.
UPDATE: An alternative way of using bc
$ bc -l <<< "7*3 - 5.5"