#!/bin/bash # calc--A command line calculator that acts as a frontend to bc setvar scale = '2' proc show_help { cat <<< """ 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, in radians l(x) natural log of x e(x) exponential log of raising e to the x j(n,x) Bessel function of integer order n of x scale N show N fractional digits (default = 2) """ } if test $Argc -gt 0 { exec scriptbc @ARGV } echo "Calc--a simple calculator. Enter 'help' for help, 'quit' to quit." /bin/echo -n "calc> " while read command args { case (command) { quit|exit { exit 0 } help|\? { show_help } scale { setvar scale = "$args" } * { scriptbc -p $scale $command $args } } /bin/echo -n "calc> " } echo "" exit 0