I often have to do some quick calculations while working on some project, and I never have a calculator when I need it. Instead, I've got a bash terminal, and up until today, I've always written an obscure perl one-liner or loaded bc to crunch the numbers.
Today I wrote a very short bash function which lets me do such calculations faster, right on the command line. Stick this in your .bashrc:
# usage: bcalc 17 / 3 + 101
# arguments have to be in quotesor escaped if there are *s etc
function bcalc {
# cheat and send it through perl.
echo "$@" | perl -ne "print eval $_;";
echo "" # force a newline.
}
I'm fully aware that eval is dangerous and the above can actually do more than just math. It's a feature!