Errata

bash Idioms

Errata for bash Idioms

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. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

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

Version Location Description Submitted By Date submitted Date corrected
Page Example 9-6: fiddle-ifs.sh
function Read_A_File

The Read_A_File function declares a local variable for the file to be read, expecting it as the first parameter:

function Read_A_File {
local file="$1"
...

But this variable is never used and the file read is obtained from the global variable IFS_TEST_FILE:

...
done < $IFS_TEST_FILE
...

I think it would be more flexible to use the parameter:

...
done < $file
...

and invoke the function that way:

...
Read_A_File $IFS_TEST_FILE
...

Note from the Author or Editor:
Great catch, thank you. You're correct, the code was supposed to be exactly as you describe, but we goofed it up. I've fixed it in the book code and the example code on Github.
* ORA: [master 73586a0] fiddle-ifs.sh: fix Read_A_File per errata 190293
* Github: [main de93a9d] fiddle-ifs.sh: fix Read_A_File per errata 190293

Miguel Macías  Feb 11, 2023 
Page Example 9-3
fancy_mapfile.sh

In the notes of the script fancy_mapfile.sh (Example 9-3) it is indicated (note 2) that

node_count="$(cat $HOSTS_FILE | wc -l)"

is not a “useless use of cat” (since it prevents the filename from appearing in the wc output). But as it is insisted in many other parts of the book, it would be faster and more efficient to avoid the execution of such a command:

node_count="$(wc -l < $HOSTS_FILE)"

Don't you think?

Note from the Author or Editor:
Another great catch, thank you again. Redirecting STDIN+ is simpler, more efficient, and more consistent with the rest of the book and our goals.

I've fixed it in the book code and the example code on Github.
* ORA: [master 241ebeb] fancy_mapfile.sh/ch09: change "cat" to "<" per errata 190326
* Github: [main d1e940f] fancy_mapfile.sh: change "cat" to "<" per errata 190326

Miguel Macías  Feb 12, 2023 
Page 26
Near bottom of code block

There is a missing single quote in `echo '` in the line after callout 15. Somehow I managed to accidentally delete it while doing copyediting revision. It is already fixed in the electronic versions and in the examples on Github, but the first print edition had already gone to the printer when I caught it.

JP Vossen  Mar 26, 2022 
Page 34
Suffix removal table

In the table of examples showing the various ways to remove from the right side of the string, the filename "img.1231.jpg" gets abbreviated to "img.1234" instead of "img.1231".

Note from the Author or Editor:
Correct, thanks for catching that. I've changed both instances of the slightly odd "1231" to "1234" to match the answer in the repo, since that seems a simpler and more expected pattern.

[master fdd190f] ch04:includes/suffix.csv: "1231" vs. "1234" bugfix per errata from Andy Lester

Andy Lester  Jul 07, 2022 
Page 37
Middle of table of parameter expansions

${var:-default} is listed twice, with two different definitions. The second occurrence should be ${var:=default}.

Note from the Author or Editor:
Nice catch, thank you! I have fixed that in the repo and pushed the fix to O'Reilly and Github.

Macon Gambill  Apr 16, 2022 
Page 43
code example for case statement.

According to bash error message: "continue: only meaningful in a `for', `while', or `until' loop".
Tested on bash version 5.2.15

That means the keyword "continue" will not work on case statement/conditional constructs.

Note from the Author or Editor:
Nice catch, thanks. I'm not sure how that incorrect `continue` got in there, and that example is only in the text, it is not in the examples directory which have automated tests.

I've fix that in the repo and also clarified the behavior of _n_ or _y_.

Andy  Aug 18, 2024 
Page 86
Top of page (pipeline starting with grep)

The first example on page 86 is identical to the last example on page 85, meaning it won't produce the expected output if executed as shown. I imagine the intent was to remove the -d':' argument from the read command and instead use prefix assignment to set IFS to ':', e.g.:

grep '^nobody' /etc/passwd | { \
IFS=':' read user shadow uid gid gecos home shell; \
echo "$user | $shadow | $uid | $gid | $gecos | $home | $shell"; }

Note from the Author or Editor:
You are correct. I've upgraded this one to serious because as written it not only does not work, but it's not at all clear why if fails.

I've committed a fix to the book code, but this one is not in the example code so that is unchanged.

Macon Gambill  Apr 24, 2022 
Page 130
second item under the first bullet point

> And unless you are using ~=, in which case you can't quote the regular expression!

"~=" should be "=~"

Note from the Author or Editor:
Thanks! This is in the a style guide file that is included in 2 places, and used to generate the `bash_idioms_style_guide.html` and `bash_idioms_style_guide.md` docs. I've fixed it in the ORA Git and on Github.

Patrick Brinich-Langlois  Sep 18, 2022 
Page 141
first sentence

"~=" is used instead of "=~"

Note from the Author or Editor:
Thanks! This is in the a style guide file that is included in 2 places, and used to generate the `bash_idioms_style_guide.html` and `bash_idioms_style_guide.md` docs. I've fixed it in the ORA Git and on Github.

Patrick Brinich-Langlois  Sep 18, 2022