Wicked Cool Shell Scripts

Wicked Cool Shell Scripts: Errata

It's inevitable, even with a team of technical and copy editors and three close proofreads of the book and production galleys as the project proceeded: there are going to be some hiccups and some typos in the book. This page contains a list of all known errata reported to-date, and if you have something you've found that you think might be a problem worth including, please don't hesitate to contact me to let me know about it.


6The book site URL is incorrectly listed as http://www.intutive.com/ I have registered the misspelled domain name and it'll work just fine, but, of course, you should use the http://www.intuitive.com/ domain instead.
13Typo:in the script validnum the line
if [ "$compressed" != "$input" ] ; then
should be modified to read:
if [ "$compressed" != "$1" ] ; then
Edit the script to change $input to $1 as shown.
13Typo: ${varname:1:1} is wrong. It should read ${varname:0:1} to access just the first character of varname
15Parameter order is incorrect: the invocation of sed to test for a valid phone number has the "-" in the wrong place. Instead of
sed 's/[^[:digit:]\(\)- ]//g'
it should instead have the "-" at the beginning:
sed 's/[^- [:digit:]\(\)]//g'
Edit the script as shown
   if [ $3 -lt 99 ] ; then
should actually be testing to see if the value is less than or equal to 99:
   if [ $3 -le 99 ] ; then
Edit the script to change -lt to -le throughout this script. This exact same error occurs on all three conditional tests (sheesh!)
25Forgotten variable expansion. In the beginning of the script, there should be a line like this:
normdate="whatever you called the normdate.sh script"
and then later in the script the line
   newdate="$(normdate "$@")"
needs one additional dollar sign so things expand properly:
   newdate="$($normdate "$@")"
Ah, well, make the changes indicated to fix the script up.
82In the script for converting temperatures, there's a spare square bracket that shows up in the sed expressions. Specifically:
sed -e 's/[-[[:digit:]]*//g'
sed -e 's/[^-[[:digit:]]*//g'
In fact, the correct expressions should be:
sed -e 's/[-[[:digit:]]*//g'
sed -e 's/[^-[[:digit:]]*//g'
Edit the script to remove the two spurious square brackets.
108In the script bestcompress you might need to change the 'ls -l' in the computation for smallest file to 'ls -lf' instead. The specific lines are:
smallest="$(ls -l "$name" $Zout $gzout $bzout | \
     awk '{print $5"="NR}' | sort -n | cut -d= -f2 | head -1)"
Edit the script to change ls -l to ls -lf as needed.
138In the script findsuid, a GNU-find specific permission string snuck in and might not work with all Unixes. Specifically, the line
for match in $(find /bin /usr/bin -type f -perm +4000 -print)
should be modified to -perm -4000 as needed.
Edit the script to change +4000 to -4000 as needed.
149In the script verifycron, in the unusual instance when a crontab entry is supposed to occur every second of every day that the system is running, the entry is denoted with five asterisks. The published script fails in this situation because of missing quotes. In the script on line 77 there's a conditional statement:
elif [ ! -z $(echo ${min%${min#?}} | sed 's/[[:digit:]]//') ] ;  then
To fix this, add quotes before the $( sequence and then again after the ) at the very end of the conditional.
Edit the script to add the quotes.
150In the script verifycron there's a glitch in the day of week check. It shows:
 # day of week check
  for dowslice in $(echo "$dow" | sed 's/[,-]/ /g') ; do
    if ! validNum $dowslice 31 ; then
      if ! validDay $dowslice ; then
        echo "Line ${lines}: Invalid day of week value \"$dowslice\""
But the value 31 should instead be 7 since it's checking day of week, not day of month, at this point.
Edit the script to change the 31 to a 7.
152In the script docron there's a glitch that shows up if you're using Mac OS X, which has a slightly different root cron format. On line 22 it lists:
    if [ -z $job ] ; then
but for Mac OS X you should have $job in quotes, thusly:
    if [ -z "$job" ] ; then
If you're on Mac OS X, edit the script to add the quotes as shown.
156In the script rotatelogs I escape the double quotes in the find conditional unnecessarily, causing the test to always return false. The old line looks like this:
   if [ -z $(find \"$back1\" -mtime +$duration -print 2>/dev/null) ]
but it should look like this:
   if [ -z $(find "$back1" -mtime +$duration -print 2>/dev/null) ]
Simply delete the two backslashes and you'll be good to go.
159In the script backup the getopts loop has a glitch which prevents you from ever seeing the usage message. It reads
while getopts "o:ifn" opt; do
  case "$arg" in
but it should read:
while getopts "o:ifn" opt; do
  case "$opt" in
to allow the usage message to appear when incorrect flags are entered.
Fix this by changing "$arg" to "$opt" in the script.
179In the script define the reference URL at Princeton has changed. The URL in the book is: url="http://www.cogsci.princeton.edu/  cgi-bin/webwn1.7.1?stage=1&word=" This can be easily corrected by updating the URL in the script to point to webwn2.0 instead of webwn1.7.1.
181Accuweather has changed its Web page format, breaking the script weather. The script read:
sed -n '/<font class="sevendayten">/,/[^[:digit:]]<\font>/p' | \
but it should now read:
sed -n '/Start - Forecast Cell/,/End - Forecast Cell/p'
Edit the script to reflect this update.
187In the script movieinfo a closing paren in the last conditional is missing. The line in the book is:
if [ ! -z "$(grep "IMDb title search" $tempout" ] ; then
but it should read:
if [ ! -z "$(grep "IMDb title search" $tempout)" ] ; then
Edit the script to add the closing paren to the conditional.
291In the script addvirtual there's an incorrect test to ensure that you're running the script as root. The line in the book is:
if [ $(id -u) != "root" -a $showonly = 0 ] ; then
but it should read:
if [ $(id -u) != 0 -a $showonly = 0 ] ; then
Edit the script to change "root" to "0".
292The format string handed to the date command has a teeny, but important mistake. The line printed in the book is:
date="$(date +%m%d%H%m ...
but it should read:
date="$(date +%m%d%H%M
Edit the script to change "m" to "M".

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)