calc - a command line calcutator
SYNOPSYS
calc 'expression'
calc is a command line calculator. It evaluates its arguments as a single awk language expression and prints the result on the standard output.
The results of the last few expressions evaluated by calc are kept in a file by default named ~/.calc. The file is used as a stack. The top value may be accessed in a calc expression as "@". Other values on the stack may be accessed with an index on "@". for example "@[2]" is the second value on the stack. The name of the stack file may be set with the -s <filename> option.
In csh it is convenient to alias calc to "=" to mimic the behavior of the IRAF cl compute mode. File name substitution can be turned off within the alias so that "*" need not be escaped within an expression and parentheses are escaped.
alias = 'set noglob;calc `echo "\!*" | sed -e s/\(/\\\(/ -e s/\)/\\\)/`;unset noglob' = 6*5 30 = (4+10)*2 28
Add a couple of number on the command line:johnpanic : calc 4 + 6 10Add a couple of number in hh:mm:ss format:johnpanic : calc 4:00:00 + 0:30:00 4:30:00Add a number to the previous answer:johnpanic : calc @ + 2:00:00 6:30:00
Undefined user written function may be automatically included in the text of programs. The environment variable TABLEFUNCTIONS names a path which is searched for undefined functions. If a function is mentioned in a user program or expression but not defined, a file found in the TABLEFUNCTIONS path with the name of the undefined function will be included in the program. This feature allows a library of usefull functions to be built and accessed easily.