#!/usr/bin/env bash # Usage: {script} RULE_FILENAME # Update list of language codes (ISO-639-2) set -euo pipefail declare -r IFS=$'\n' declare -r URL="http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt" declare -r RULE_FILENAME="${1}" declare -r TEMPORARY_LIST=$(mktemp) download_list() { echo "Downloading list from '${URL}'" curl --silent --location "${1}" --output "${2}" } update_currency_codes() { local -r filename_rule="${1}" local -r filename_list="${2}" local -r temporary_rule=$(mktemp) echo "Updating list in '${filename_rule}'" { sed -n '/^ "${temporary_rule}" mv "${temporary_rule}" "${filename_rule}" } download_list "${URL}" "${TEMPORARY_LIST}" update_currency_codes "${RULE_FILENAME}" "${TEMPORARY_LIST}"