#24 An Interactive Calculator

Once I wrote Script #9, allowing command-line invocations of bc for floating-point calculations, it was inevitable that I'd write a small wrapper script to create an interactive command-line-based calculator. What's remarkable is that, even with help information, it's very short.

The Code

 #!/bin/sh # calc - A command-line calculator that acts as a front end to bc. scale=2 show_help() { cat << EOF In addition to standard math functions, calc also supports a % b remainder of a/b a ^ b exponential: a raised to the b power s(x) sine of x, x in radians c(x) cosine of x, x in radians a(x) arctangent of x, returns radians l(x) natural log of x e(x) exponential log of raising e to the x j(n,x) bessel function of integer ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.