command line calculator

Racer D

what?
this might be a simple one, but I can't find it anywhere. I'd like a calculator that I could execute from shell. I've tried some calculators which take me to their special shell when I invoke them. and I have to exit them to get back to my shell. I'd like something that would work like ls or cat command.
so like this
Code:
Welcome to Darwin!
[racer:~] racer% calc 1+1
2
[racer:~] racer%

know what I mean? must support some of the "more complex" functions like brackets and knowing that * comes before +

anyone? :)
 
I think there's a command-line pgm called "dc" that is sort of a command-line calculator, but it's not real intuitive. You'd use it sorta like this:

2 (enter)
3 (enter)
+ (enter)
= (enter)
(output) 5

I emphasize **SORTA** that's not actually the correct syntax, but it's close. Try man dc....
 
You really should use 'bc' instead. It's the standard application to use from a shell for math. 'man bc' will give you more information. Using the awk alias thingy only works with specific versions of awk, so it may work fine on OS X, but if you're on another OS it may not. It also doesn't work with shells other the csh/tcsh.

Brian
 
btoneill: I really don't like bc beahviour. It doesn't calculate directly from my shell, but takes me into it's own shell where I type in calculations. And I have to use quit to get back to my shell. I like how that awk thingie just returns the result while still in my shell.
It might not work on other systems or shells, but awell I'll only use it on my os x & csh :)
 
Racer - you ought to be able to pipe to bc just as easily as to awk. Although, the awk thing looks fine...
 
Back
Top