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

Create a command-line calculator UNIX
I love this, even though I didn't think of it myself. ;-)

Want a simple calculator that works at the Terminal prompt? As per the suggestion on this website, just put this in your ".cshrc" (or "aliases.mine" as the case may be):
alias calc 'awk "BEGIN{ print \!* }" ' 
That's it. Then run
% source .cshrc
% rehash
and you can do basic arithmetic in the Terminal application:
% calc 545+56
% calc 545-56
% calc 545*56
% calc 545/56
I like this especially because now I don't have to use the wretched Numlock key on my iBook.
  • Currently 3.50 / 5
  You rated: 2 / 5 (2 votes cast)

Create a command-line calculator | 6 comments | Create New Account
Click here to return to the 'Create a command-line calculator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Authored by: cinco on Dec 31, '01 10:15:41AM

You should use nCalc1.3.1b with your powerbook, or ibook... Russ Martin Rocks!!

"It lets you use the embedded keypad on an Apple notebook computer (iBooks & PowerBooks) without having to worry about whether the Num Lock (F5) key is switched on or off."

You can get in at

[ Reply to This | # ]
Authored by: Anonymous on Dec 31, '01 11:26:49AM

Or just use '"bc"

[ Reply to This | # ]
Use bc as an alternative...
Authored by: rmuir on Dec 31, '01 12:12:21PM
Included with in my OS X goodies is the all-too-common *nix inclusion of "bc" (/usr/bin/bc). It is available anytime at the command prompt. I remember this command as standing for "basic calculator".

Read about the bc command by typing "man bc"...

Here's a sample output:
[home1:~] rmuir% bc -q
[home1:~] rmuir%

Lots easier than adding an entry to your .cshrc file...

[ Reply to This | # ]
Use bc as an alternative...
Authored by: mudmonkey on Dec 31, '01 12:15:43PM

Aaaah, bc, how long has it been...

Don't forget 'dc' which is pretty much the same thing, but, reverse polish.

These commands are FAR more powerful than creating awk aliases to do simple arithmetic.

[ Reply to This | # ]
Use bc as an alternative...
Authored by: Paul Burney on Dec 31, '01 01:27:29PM

Of course, you could also add an alias:

alias bc "bc -q"

into your.cshrc file to save 60% in typing time. :-)

[ Reply to This | # ]
Alternate use of calc/bc
Authored by: evancm on Dec 31, '01 04:34:58PM
I prefer the calc contruct to using 'bc' raw, and because I'm using bash, the alias in the example given doesn't seem to work. So, I added this entry to my .profile to do this:
     echo $* | bc

[ Reply to This | # ]