Wicked Cool Shell Scripts
Wicked Cool Shell Scripts :: shell script 067-getstock.sh

Shell Script 067-getstock.sh

#!/bin/sh

# getstock - given a stock ticker symbol, return its current value
#    from the Lycos web site

url="http://finance.lycos.com/qc/stocks/quotes.aspx?symbols="

if [ $# -ne 1 ] ; then
  echo "Usage: $(basename $0) stocksymbol" >&2 
  exit 1
fi

value="$(lynx -dump "$url$1" | grep 'Last price:' | \
  awk -F: 'NF > 1 && $(NF) != "N/A" { print $(NF) }')"

if [ -z $value ] ; then
  echo "error: no value found for ticker symbol $1." >&2
  exit 1
fi

echo $value

exit 0

Explore The Book!
[book cover]
Table of Contents
Read Some Scripts!
Shell Script Library
Book Errata
All The Links
Read the Reviews
Talk About It
Author Bio
Buy The Book!



Other books by author Dave Taylor
Learning Unix for Mac OS X (O'Reilly & Associates)
Solaris 9 for Dummies (Wiley)
Teach Yourself Unix in 24 Hours (Sams/Macmillan)
Teach Yourself Unix System Administration in 24 Hours (Sams/Macmillan)
Creating Cool HTML 4 Web Pages (Wiley)
Ten Quick Steps to Learning Mac OS X Unix (ebook!)