#!/bin/sh -u # \$0 [team] # Fetch some team sports scores from ESPN and do some math on them. # Written in-class December 2018 based on suggestions from students. # -Ian! D. Allen - idallen@idallen.ca - www.idallen.com # Standard script header for this course: PATH=/bin:/usr/bin ; export PATH umask 022 # If no arguments, assume Ottawa team if [ "\$#" -eq 0 ] ; then team=ott else team=\$1 fi # Fetch the ESPN page for the requested team and output only the Win/Lose lines: list=\$( elinks -dump -dump-width 999 -no-numbering -no-references "http://www.espn.com/nhl/team/schedule/_/name/\$team" | grep -o '^.* [WL][0-9][^ ]*' ) # Count the home scores: home=\$( echo "\$list" | fgrep ' vs ' ) hwins=\$( echo "\$home" | awk '{ print \$NF }' | fgrep -c 'W' ) hlose=\$( echo "\$home" | awk '{ print \$NF }' | fgrep -c 'L' ) # Count the away scores: away=\$( echo "\$list" | fgrep ' @ ' ) awins=\$( echo "\$away" | awk '{ print \$NF }' | fgrep -c 'W' ) alose=\$( echo "\$away" | awk '{ print \$NF }' | fgrep -c 'L' ) # Totals twins=\$(( hwins + awins )) tlose=\$(( hlose + alose )) # Output section. echo "\$team: HWin \$hwins HLose \$hlose" echo "\$team: AWin \$awins ALose \$alose" echo "\$team: TWin \$twins TLose \$tlose" if [ "\$twins" -lt "\$tlose" ] ; then echo "DON'T BET ON TEAM \$team" else echo "BET ON THIS TEAM \$team" fi