Recovered old changelog from 2011
[curcy.git] / curcy
1 #!/usr/bin/env bash
2
3 set -e
4
5 if [ -z "$1" ]; then
6     echo "You must give an international currency code as a parameter, such as USD" >&2
7     exit 1
8 fi
9
10 local_currency=`locale int_curr_symbol`
11 if [ -z "$local_currency" ]; then
12     echo "Can't find you locale currency code" >&2
13     exit 1
14 fi
15
16 local_currency_value=`grep ^$local_currency /var/currencies | cut -d \  -f 2`
17 if [ -z "$local_currency_value" ]; then
18     echo "You currency $local_currency is unavailable in exchange rate database" >&2
19     exit 1
20 fi
21 #echo "1 euro = $local_currency_value $local_currency"
22
23 target_currency=$1
24 target_currency_value=`grep ^$target_currency /var/currencies | cut -d \  -f 2`
25 if [ -z "$target_currency_value" ]; then
26     echo "The currency $target_currency is unavailable in exchange rate database" >&2
27     exit 1
28 fi
29 #echo "1 euro = $target_currency_value $target_currency"
30
31 rate1=`echo "scale=4;$local_currency_value/$target_currency_value" | bc`
32 rate2=`echo "scale=4;$target_currency_value/$local_currency_value" | bc`
33 echo "1 $local_currency = $rate1 $target_currency"
34 echo "1 $target_currency = $rate2 $local_currency"