#!/bin/ksh # /bin/ksh works as-is on both Linux and SCO, but could also use /bin/sh on # Linux, or /usr/local/bin/bash on SCO # Temperature Converter v.01.1 # By Behzad Mirbagheri # behzadm@home.com # - converted from perl to ksh, mostly so I could add a non-interactive mode # I wanted, since I don't know perl. # - updated to use bc to handle decimal degrees given by lm_sensors /proc file. # - linut@squonk.net usage () { echo "tempconv - converts a value to/from degrees Farenheit from/to" echo " degrees Celcius." echo "usage:" echo "tempconv [ ] | [h|help|-h|--help]" echo "" echo "with no options, it interactively prompts for values." echo "or you can give it the necessary info on the command line very simply" echo "and automatically get the right answer back with no other output, for" echo "use in scripts. Examples:" echo "You have a temperature reading from your motherboard cpu sensor in" echo "degrees C. You want to know what that is in degrees F..." echo "you type: tempconv 24 c" echo "tempconv returns: 75" echo "tempconv --help or -h or h or help shows this message." echo "" exit 1 } case $1 in h|help|-h|--help) usage ;; esac i=false t=$1 f=$2 [ -z "$t" -o -z "$f" ] && i=true $i && { echo "Temperature Converter" echo "To Convert from Fahrenheit to Celsius press f" echo "To Convert from Celsius to Fahrenheit press c" read f } case $f in f) $i && { echo "Fahrenheit to Celsius..." echo "Now enter the temperature (in F) you would like to convert" read t } tconv=`echo "($t - 32) * 5 / 9 " |bc` $i && echo -en "The Temperature in Celsius is " echo "$tconv" ;; c) $i && { echo "Celsius to Fahrenheit..." echo "Now enter the temperature (in C) you would like to convert" read t } tconv=`echo "$t * 9 / 5 + 32 " |bc` $i && echo -en "The Temperature in Fahrenheit is " echo "$tconv" ;; *) usage exit 1 ;; esac