#!/bin/sh file="$XDG_CACHE_HOME/forex.units" oneday=$((24 * 3600)) now=$(date +%s) then=$(stat -qf %m "$file") # if file doesn't exist, $then is 0 type curl unzip >/dev/null || { echo "${0##/}: make sure curl, unzip and units are installed" >/dev/stderr exit 1 } test $((now - then)) -gt $oneday && { curl -s 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip' | unzip -p /dev/stdin | awk -F ', ' ' # first field is date, last field is empty NR == 1 { for (i=2; i "$file" } test -f "$file" && units -f "$file" "$@"