2018-12-15 21:24:42 -08:00
|
|
|
#!/usr/bin/bash
|
2018-08-27 13:30:54 -07:00
|
|
|
# Obtain a weather forecast
|
|
|
|
|
2018-09-14 10:20:21 -07:00
|
|
|
printHelp() {
|
|
|
|
cat << EOF
|
|
|
|
Retrieve the weather of a give location
|
|
|
|
|
|
|
|
Usage: getweather [-h|--help] [location]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h show this help page
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "${1}" in
|
|
|
|
"-h"|"--help")
|
|
|
|
printHelp
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
2018-09-15 02:40:20 -07:00
|
|
|
-*)
|
2018-09-14 10:20:21 -07:00
|
|
|
echo "Not an option: ${1}" >&2 && exit 1
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-12-15 21:24:42 -08:00
|
|
|
[[ ! -x '/usr/bin/curl' ]] && echo 'curl is required for this script' && exit 1
|
2018-09-14 10:20:21 -07:00
|
|
|
[[ -z "${@}" ]] && echo "Please enter a location" >&2 && exit 1
|
|
|
|
|
|
|
|
xargs --no-run-if-empty -I {} curl wttr.in/{} <<< "${@}"
|