#!/usr/bin/env etsh : : etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: c6d78a3c9df262cb840344ebd9aaf68a154c0281 $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " Calculate 3 unknown values representing the size of a circle " : " starting from 1 known value which is specified by the user. " : " Print the resulting values of the area, circumference, " : " diameter, and radius to the standard output. " : : " usage: circalc {-a | -c | -d | -r} number " : : : " Check for correct usage. " : : >>$0'' <'' ; : >>$1'' <'' ; : >>$2'' <'' killer $0 circalc if $# != 2 -o ! \( \ X$1 = X-a -o X$1 = X-c -o X$1 = X-d -o X$1 = X-r \ \) if { exit } pusage $0 '"{-a | -c | -d | -r} number"' : : " Ensure that $2 is either an integer or a floating-point number. " : echo $2 | egrep '^(0|0\.[0-9]+|[1-9][0-9]*|[1-9][0-9]*\.[0-9]+)$' >/dev/null if $? != 0 if { exit } perror $0 $2'": Not a number >= 0"' if X$1 != X-a goto $1 : fallthrough : -a - " Solve circumference, diameter, and radius from area. " echo ' Area: '$2 echo -n 'Circumference: ' echo 'scale = 5 ; 3.14159 * 2 * sqrt ( '$2' / 3.14159 )' | bc echo -n ' Diameter: ' echo 'scale = 5 ; 2 * sqrt ( '$2' / 3.14159 )' | bc echo -n ' Radius: ' echo 'scale = 5 ; sqrt ( '$2' / 3.14159 )' | bc exit : -c - " Solve diameter, radius, and area from circumference. " echo -n ' Area: ' echo 'scale = 5 ; 3.14159 * ( '$2' / ( 3.14159 * 2 ) ) ^ 2' | bc echo 'Circumference: '$2 echo -n ' Diameter: ' echo 'scale = 5 ; '$2' / 3.14159' | bc echo -n ' Radius: ' echo 'scale = 5 ; '$2' / ( 3.14159 * 2 )' | bc exit : -d - " Solve circumference, radius, and area from diameter. " echo -n ' Area: ' echo 'scale = 5 ; 3.14159 * ( '$2' / 2 ) ^ 2' | bc echo -n 'Circumference: ' echo 'scale = 5 ; 3.14159 * 2 * ( '$2' / 2 )' | bc echo ' Diameter: '$2 echo -n ' Radius: ' echo 'scale = 5 ; '$2' / 2' | bc exit : -r - " Solve circumference, diameter, and area from radius. " echo -n ' Area: ' echo 'scale = 5 ; 3.14159 * '$2' ^ 2' | bc echo -n 'Circumference: ' echo 'scale = 5 ; 3.14159 * 2 * '$2 | bc echo -n ' Diameter: ' echo 'scale = 5 ; 2 * '$2 | bc echo ' Radius: '$2