2 changed files with 42 additions and 0 deletions
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash |
||||
|
||||
# |
||||
# Simple currency converter |
||||
# |
||||
|
||||
SHORT_OUTPUT=false |
||||
|
||||
exchange() { |
||||
local api_url="https://api.exchangeratesapi.io/latest?base=${1^^}&symbols=${2^^}" |
||||
|
||||
curl -s -q -L "$api_url" \ |
||||
| jq -r --arg short "$SHORT_OUTPUT" ' |
||||
def round: |
||||
.*100.0 + 0.5 | floor / 100.0; |
||||
|
||||
if ($short == "true") then |
||||
.rates | to_entries | .[] | (.value | round | tostring) |
||||
else |
||||
"1 " + .base + " ≈ " |
||||
+ (.rates | to_entries | .[] | (.value | round | tostring) + " " + .key) |
||||
end |
||||
' |
||||
} |
||||
|
||||
if [ $# -le 1 ]; then |
||||
echo "USAGE: $(basename "$0") ?-s? FROM TO1,TO2,...,TOn" |
||||
echo " e.g: $(basename "$0") ?-s? USD EUR,RUB" |
||||
echo "Set -s to show only value." |
||||
else |
||||
if [ "$1" == "-s" ]; then |
||||
SHORT_OUTPUT=true |
||||
shift |
||||
fi |
||||
|
||||
exchange "$@" |
||||
fi |
||||
|
Loading…
Reference in new issue