Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A simple 'graphical' calculator script for Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A simple 'graphical' calculator script for Terminal
Authored by: mikebremford on Mar 16, '06 02:47:18AM
I knocked up a tcsh alias years ago so I could do "calc (5*3)+2" from the command line - for those running csh, try:
alias calc 'echo "scale=4; \!*" | bc | sed "s/^\(-\)*\./\10./"'
However recently I switched to zsh, so wrote the following which is the equivalent. The alias-to-a-function is so I can get the noglob in there, which is necessary to use '*' from the command line:
alias calc="noglob __calc"
__calc() {
    echo "scale=4; $*" | bc | sed "s/^\(-\)?\./\10./"
}
It's not graphical but if you're in a terminal, who cares?

[ Reply to This | # ]