Simple command-line calculator for tcsh/bash :
TCSH/CSH :
I have for some year used a simple alias for the calculator command.
The alias only requires awk, and that tcsh (or csh) is the running
hell. This alias will not work with bash/sh/ksh since these shells
do not allow arguments in aliases. Just place the following line in
your ~/.tcshrc or type at the prompt:
alias calc 'awk "BEGIN{ print \!* }" '
# When calling calc DO NOT escape "*":
# Example: calc (3+5)*4/5
BASH:
At a recent meeting in SSLUG (1997) I was given the idea to use functions
for making a bash equivalent of the above "calc" alias. In ~/.bash_profile
:
function calc () {
awk "BEGIN { print $* ; }"
}
It is nescesary to use quotes if the expression contains () or * :
calc "(3+5) * 4/5"