/
2745.html
155 lines (142 loc) · 3.58 KB
/
2745.html
1
<h3>Errata</h3><h1>Shell Scripting Recipes</h1><h2>A Problem-Solution Approach</h2><h3>by Chris F.A. Johnson</h3><h2>Chapter 1</h2><h4>standard-vars</h4><p> <b>Page 9</b><br> For the sake of consistency with the code that supposedly created the file, the lines from "standard-vars" should read:<pre>NL="""R="TAB=" "</pre><h4>Bourne Shell Expansions</h4><p> A number of newlines are missing from this section, starting with the last line of <b>Page 12</b> which should be:<pre>$ echo /$var-y//y/</pre> <b>Page 13</b><br><pre>$ echo /${var+C}//X/ Finally, when the variable is set and not null, VALUE is used, withor without the colon.$ var=A$ echo /${var:+X}//X/$ echo /${var+X}//X/</pre> An extra comma appears on <b>Page 14</b>; it should be:<pre>> list=${list:+$list,}$f</pre><p>Thanks to Jens Schweikhardt for pointing out the errors in Chapter 1.</p><h2>Chapter 3</h2><h4>Notes: gsub()</h4><p>On <b>Page 72</b> the '_gsub' function under "Notes" should be:</p><pre>_gsub() { _GSUB=${1//"$2"/"$3"}; }</pre><h2>Chapter 5</h2><h4>3. Convert Degrees Celsius to Fahrenheit</h4><b>Page 126</b>, in the c2f (not '_c2f') function, '_C2F=' should beremoved:<pre>c2f(){ prompt="Degrees Celsius" arg "$@" echo "$arg" | awk '{ printf "%" pr "f\n", $1 * 1.8 + 32 }' pr=${precision:-.2}}</pre><p><b>Page 129</b>, in the cm2i (not '_cm2i') function, 'Millimeters'should be 'Centimeters', and the function call and variable in thelast two lines of 'mm2i' are wrong.</p><pre>cm2i(){ units=inches prompt=Centimeters arg "$@" _cm2i "$arg" printf "%s%s\n" "$_CM2I" "${units:+ $units}"}</pre><p><b>Convert Millimeters to Inches</b><pre>mm2i(){ units=inches prompt=Millimeters arg "$@" _mm2i "$arg" printf "%s%s\n" "$_MM2I" "${units:+ $units}"}</pre><h4>The Lengths and Distances Menu</h4><p><b>Page 134</b>, the last item on the menu should be:<pre> 8. mm2i - millimeters to inches</pre><p>David Emme provided the corrections to Chapter 5; thanks, David.</p><h2>Chapter 15</h2><h4>_put_csv</h4><p>On <b>Page 312</b>, the '_put_csv' function didn't deal with leadingnull fields. Gregg Nelson provided a fix:<pre>_put_csv(){ _PUT_CSV= for field in "$@" ## loop through the fields (on command line) do case $field in ## If field contains non-numerics, enclose in quotes *[!0-9.-]*) _PUT_CSV=$_PUT_CSV\"$field\", ;; '') _PUT_CSV=$_PUT_CSV, ;; *) _PUT_CSV=$_PUT_CSV$field, ;; esac done _PUT_CSV=${_PUT_CSV%,} ## remove trailing comma}</pre><h2>Chapter 20</h2><p>In the install_script() function on <b>Page 402</b>, the variable'$file' should be '$1', and the path should be removed:<pre> filename=${1%$devel_suffix} ## Command name, without suffix filename=${filename##*/} ## Remove path; use file name alone</pre><p>Also in the install_script() function, on <b>Page 403</b>, removingwrite permissions from the script can cause problems in someinstances. If they do, just remove them or comment them out:<pre># ## Remove write permissions# chmod +rx,-w "$dest"</pre><h4>_uniqfile()</h4><p>A function was missing from the cpsh script on <b>Page 403</b>.This should be inserted before "progname=${0##*/}".<pre>_uniqfile(){ _base=$1 _n=1 while [ -f "$_UNIQFILE" ] || [ -d "$_UNIQFILE" ] do _zpad $_n ${VERSION_WIDTH} _UNIQFILE=$_base-$_ZPAD _n=$(( $_n + 1 )) done}</pre>