#!/bin/bash read ICAO if ! echo "$ICAO" | grep -Eq "^([A-Z]|[a-z]){4}$" ; then echo "error: invalid ICAO code!" exit 1 fi xmllint --xpath 'string(/response/data/METAR/raw_text)' <(curl -s "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=$ICAO&hoursBeforeNow=1") | head -n1