A simple 'graphical' calculator script for Terminal

Mar 13, '06 07:22:00AM

Contributed by: Pedro Estarque

It has always annoyed me that a simple calculator would take several seconds to load on my current machine, and yet MacOS Classic's calculator is instantaneous even on my 33mhz 68k Mac. xcalc is also instantaneous, but requires x11 to load, which takes a while.

As I'm always running Terminal.app anyway, I thought a terminal calculator with a 'GUI' would be nice. After googling for it with no luck, I decided to write a shell script that mimics the behavior of a simple calculator. It loads instantly even on a iMac 233, although screen redraw can be a little sluggish on such hardware.

Here's what it looks like, and the result of your calculation is copied to the clipboard.

I'm not a developer in any way, so the code is probably the ugliest thing ever written, but it works for me. It handles only the basic 4 operations with 5 decimal cases. type 'q' to quit, the rest should be self explainable. Improvements are more than welcome -- for example, I couldn't map the clear key in the numeric pad, so I used 'c' for clear.

[robg adds: I mirrored the script here on hints. Remember to make it executable first (chmod a+x tcalc). I tested it, it seems to work well, and it is indeed speedy.]

Comments (18)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060309133147386