weather 505 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. function usage() {
  5. echo "Usage: weather [OPTION] [location]"
  6. echo " -1 Print weather forecast for 1 day"
  7. echo " -a Print all weather forecasts"
  8. echo " -h Display this help message"
  9. exit 1
  10. }
  11. lines="1,7"
  12. OPTIND=1
  13. while getopts ":1ah" opt; do
  14. case $opt in
  15. 1) lines="1,17" ;;
  16. a) lines="" ;;
  17. h) usage ;;
  18. ?) echo "Unknown option: $OPTARG"; usage ;;
  19. esac
  20. done
  21. shift $((OPTIND-1))
  22. curl -s wttr.in/${1:-} | sed -n "$lines"p