Six-module walkthrough covering navigation, files, reading/searching, processes/editors, scripting, and advanced tools (ssh, regex, tar, etc.). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
538 B
Bash
Executable file
31 lines
538 B
Bash
Executable file
#!/bin/bash
|
|
# weather.sh [-s STATE] [ZONE]
|
|
|
|
usage() { echo "Usage: $0 [-s STATE] [ZONE]" 1>&2; exit 1; }
|
|
|
|
STATE="de"
|
|
ZONE="001"
|
|
|
|
while getopts "s:" flag; do
|
|
case "$flag" in
|
|
s) STATE="$OPTARG" ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
shift $((OPTIND - 1))
|
|
|
|
# Allow 0 or 1 positional arg (ZONE)
|
|
if [ "$#" -gt 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
if [ "$#" -eq 1 ]; then
|
|
if [[ ! "$1" =~ ^[0-9]{3}$ ]]; then
|
|
usage
|
|
fi
|
|
ZONE="$1"
|
|
fi
|
|
|
|
STATE="${STATE,,}" # lowercase
|
|
|
|
curl -s "https://tgftp.nws.noaa.gov/data/forecasts/zone/${STATE}/${STATE}z${ZONE}.txt"
|