dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit c217042e721f497b7106e72f6357cef543b43bc8
parent 5e38d4a528a6f66062e48f8fc94ad7ce514c5133
Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date:   Tue, 26 Apr 2016 15:04:18 -0700

add command line currency conversion

Diffstat:
Abin/currency | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/bin/currency b/bin/currency @@ -0,0 +1,29 @@ +#!/bin/bash -e + +if [ $# -lt 1 ]; then + echo -e "Usage: $0 [amount] [currency1] [currency2]\n" + echo "If currency1 and currency2 and are not defined they default to USD and DKK, respectively." + echo -e "Currency strings are not case-insensitive. The amount defaults to 1.\n" + echo "Example 1: $0 USD GBP" + echo "Example 2: $0 42" + echo "Example 3: $0 GBP EUR 14" + exit 0 +fi + +toUpper() { + echo $@ | tr "[:lower:]" "[:upper:]" +} + +if [ -n "$1" ]; then A=$1; else A=1; fi +if [ -n "$2" ]; then FROM=$(toUpper "$2"); else FROM=USD; fi +if [ -n "$3" ]; then TO=$(toUpper "$3"); else TO=DKK; fi +if [ $TO == $FROM ]; then echo "Nothing to do!"; exit 2; fi + +CONVERTER="http://www.google.com/finance/converter?a=$A&from=$FROM&to=$TO" +#echo $CONVERTER + +RESULT=`wget -nv -O - "$CONVERTER" 2>&1 | \ + sed -n -e 's/.*<span class=bld>\(.*\)<\/span>.*/\1/p'` + +#echo "Result: $A $FROM = $RESULT" +echo $RESULT