Linux, Unix, /etc

Danger Will Robinson! You are now entering a condescending Unix user zone!
Sponsored links (requires javascript):

Scripts: Simple Databases

A set of simple scripts that look up values in flat file databases. Trivial, but handier than looking them up in the back of the dictionary, or, in the case of exchange rates, having to fire up the browser and go out on the web.

Exchange Rates

Well, contra the above, my exchange rates look-up now does use the web! Now that I have a 24/7 connection, there seemed no point in not doing so. Note that the last line is all one — don't break it up if you decide to use this.

#!/bin/sh
#currconv: currency converter
case $# in
    3) ;;
    *) 1>&2 echo "currconv: currconv amount from to"; exit 1;;
esac
lynx -dump -cookies -cmd_script=$HOME/scripts/xe.com.lynx "http://www.xe.com/ucc/convert.cgi?Amount=$1&From=$2&To=$3" | sed -n '/Live/{n;p;n;p;n;p;n;p;n;p;}'


simple table-driven units conversions

It's simple to write little programs to use tables to do units conversion.

lengthconv: weight converter

 
#!/bin/sh
#weightconv: weights & measures converter
progname=`basename $0`
table=/usr/local/lib/weights_and_measures
case $# in
    0|1) echo "$progname: 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 "$progname: no rate found for $from to $to" 1>&2; exit 2;;
esac
echo $amount $rate | awk '{print $1*$2}'

weightconv: length converter

 
#!/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}'


[back to Scripts index] [back to Linux, Unix, etc] [Main Site] [Weblog]



Contents licensed under the GPL