#!/bin/sh -u # A weather script to show the current temperature in Ottawa (YOW) #------------------------------------------------------------------ # Syntax: $0 (no command line arguments used) #------------------------------------------------------------------ # Purpose: # Display the current weather for city code YOW (Ottawa). #------------------------------------------------------------------ # Student Name: Ben Dover # Algonquin EMail Address: abcd0001 # Student Number: 074-210-779 # Course Number: DAT2330 # Lab Section Number: 014 # Professor Name: Ian Allen # Assignment Name/Number/Date: This is a sample exercise label # Comment: This is a sample. #------------------------------------------------------------------ # Set a standard shell search path and a friendly umask. # PATH=/bin:/usr/bin ; export PATH umask 022 # Note the need to quote the URL because of the shell metacharacter. # Save the lynx formatted output in a shell variable for later processing. # url='http://text.weatheroffice.ec.gc.ca/forecast/city_e.html?on-118' page=$( lynx -dump "$url" ) # Note: we should check the contents of $page for errors here ... # Send the saved page contents through grep twice to fetch two lines. # Command substitution captures the line output by grep. # templine=$( echo "$page" | grep -A 1 -e 'Temperature:' | tail -1 ) obsline=$( echo "$page" | grep 'Observed ' ) # Echo the output through tr to compress multiple blanks into one. # echo "$obsline --> $templine" | tr -s ' '