parent
270a9346ed
commit
2446e10360
|
@ -1,53 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ -z "$AGENT" ] && AGENT='curl -sA "Mozilla/5.0"'
|
||||
|
||||
if [ "$1" = "-l" ]; then
|
||||
$AGENT 'https://www.google.com/finance/converter' \
|
||||
| awk -F'<|>|"' '/select name=from value/, /\/select/ {if ($5 != "") {sub(/\(.*\)/, "", $5); print $3, $5}}'
|
||||
exit
|
||||
fi
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/} IN-CURRENCY OUT-CURRENCY [VALUES...]
|
||||
${0##*/} -l
|
||||
|
||||
Convert VALUES from IN-CURRENCY to OUT-CURRENCY.
|
||||
VALUES are read from stdin if not provided.
|
||||
|
||||
CURRENCY is a 3-letters code like EUR, SEK, USD, etc.
|
||||
See the list of codes with the '-l' option.
|
||||
|
||||
The download agent is specified from environment variable AGENT='$AGENT'.
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
|
||||
change="$($AGENT "http://www.google.com/finance?q=$1$2" | \
|
||||
awk -F '<|>' '/^1 / {print substr($3, 1, index($3, " "))}')"
|
||||
|
||||
if [ -z "$change" ]; then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
|
||||
shift 2
|
||||
|
||||
mul() {
|
||||
[ -n "$1" ] && [ -n "$2" ] && awk "BEGIN {print $1*$2}"
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
while read v; do
|
||||
mul $v $change
|
||||
done
|
||||
else
|
||||
for v; do
|
||||
mul $v $change
|
||||
done
|
||||
fi
|
Loading…
Reference in New Issue