Home  >  Magazine  >  #65 September 1999  >  Filters  >  Listing 2.
July 23, 1999 | Last Updated 3:00pm

Listing 2. weightconv Script

#!/bin/sh
#weightconv: weights & measures converter
table=/usr/local/lib/weights_and_measures
case $# in
    0|1) echo "weightconv: usage weightconv\
 amount from [to]" 1>&2; exit 1;;
esac
amount=$1
from=$2
to=$3
rate=`grep "^$from	$to" $table|
  awk '{print $3}'`
case $rate in
    "") echo "weightconv: no rate found for\
 $from to $to" 1>&2; exit 2;;
esac
echo $amount $rate | awk '{print $1*$2}'