Errata

bash Cookbook: Rough Cuts Version

Errata for bash Cookbook: Rough Cuts Version

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 112
Top of the page, first sentence.

It states the shell builtin variable is ${} when instead I think it was intended to mention the shell builtin variable $#. This solution talks about how to easily check the count of positional parameters given to a script.

Jessie Saenz  Jul 16, 2021 
Printed Page 125
Last line.

I believe '(because of the #)' is inserted in the middle of the sentence where it doesn't make sense. A few words after this presumed mistake is seen the intended '(because of the double ##)' text which applies to the solution above demonstrating the ${##} operator (not the ${#} operator).

Jessie Saenz  Jul 16, 2021 
Printed Page 150
Towards the top above the Scorpion picture.

At least as of bash version 5.1.4(1)-release:

I cannot get bash to match any regular expressions with-in double quotes, which the example in the book shows. Also, omitting the double quotes using the regular expression in the book produces errors. To get the regular expression from the book to work you must not use double quotes and you have to escape any space with a backslash. Below is what works:

for CDTRACK in *
do
if [[ "$CDTRACK" =~ ([[:alpha:][:blank:]]*)-\ ([[:digit:]]*)\ -\ (.+)$ ]]
then
echo Track ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]}
mv "$CDTRACK" "Track${BASH_REMATCH[2]}"

fi
done

*I did all my testing using only if statements, I did not use a for loop.

Jessie Saenz  Jul 26, 2021