fixes to read/wait; revert change that processes $'...' quoting in here-documents unconditionally

This commit is contained in:
Chet Ramey
2022-01-24 09:37:14 -05:00
parent 2a1c81bf63
commit 3011048a92
38 changed files with 9824 additions and 6133 deletions
+48 -28
View File
@@ -4,9 +4,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This text is a brief description of the features that are present in
the Bash shell (version 5.2, 26 December 2021).
the Bash shell (version 5.2, 17 January 2022).
This is Edition 5.2, last updated 26 December 2021,
This is Edition 5.2, last updated 17 January 2022,
of The GNU Bash Reference Manual,
for Bash, Version 5.2.
@@ -77,10 +77,10 @@ Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a>, Previou
<span id="Bash-Features-1"></span><h1 class="top">Bash Features</h1>
<p>This text is a brief description of the features that are present in
the Bash shell (version 5.2, 26 December 2021).
the Bash shell (version 5.2, 17 January 2022).
The Bash home page is <a href="http://www.gnu.org/software/bash/">http://www.gnu.org/software/bash/</a>.
</p>
<p>This is Edition 5.2, last updated 26 December 2021,
<p>This is Edition 5.2, last updated 17 January 2022,
of <cite>The GNU Bash Reference Manual</cite>,
for <code>Bash</code>, Version 5.2.
</p>
@@ -2845,45 +2845,65 @@ and the &lsquo;<samp>/</samp>&rsquo; following <var>pattern</var> may be omitted
any unquoted instances of &lsquo;<samp>&amp;</samp>&rsquo; in <var>string</var> are replaced with the
matching portion of <var>pattern</var>.
This is intended to duplicate a common <code>sed</code> idiom.
Backslash is used to quote &lsquo;<samp>&amp;</samp>&rsquo; in <var>string</var>; the backslash is removed
</p>
<p>Quoting any part of <var>string</var> inhibits replacement in the
expansion of the quoted portion, including replacement strings stored
in shell variables.
Backslash will escape &lsquo;<samp>&amp;</samp>&rsquo; in <var>string</var>; the backslash is removed
in order to permit a literal &lsquo;<samp>&amp;</samp>&rsquo; in the replacement string.
Pattern substitution performs the check for &lsquo;<samp>&amp;</samp>&rsquo; after expanding
<var>string</var>,
so users should take care to quote backslashes intended to escape
the &lsquo;<samp>&amp;</samp>&rsquo; and inhibit replacement so they survive any quote removal
performed by the expansion of <var>string</var>.
For instance,
Users should take care if <var>string</var> is double-quoted to avoid
unwanted interactions between the backslash and double-quoting, since
backslash has special meaning within double quotes.
Pattern substitution performs the check for unquoted &lsquo;<samp>&amp;</samp>&rsquo; after
expanding <var>string</var>,
so users should ensure to properly quote any occurrences of &lsquo;<samp>&amp;</samp>&rsquo;
they want to be taken literally in the replacement
and ensure any instances of &lsquo;<samp>&amp;</samp>&rsquo; they want to be replaced are unquoted.
</p>
<p>For instance,
</p>
<div class="example">
<pre class="example">var=abcdef
rep='&amp; '
echo ${var/abc/&amp; }
echo &quot;${var/abc/&amp; }&quot;
echo ${var/abc/&quot;&amp; &quot;}
echo ${var/abc/$rep}
echo &quot;${var/abc/$rep}&quot;
</pre></div>
<p>will display three lines of &quot;abc def&quot;, while
<p>will display four lines of &quot;abc def&quot;, while
</p>
<div class="example">
<pre class="example">var=abcdef
rep='&amp; '
echo ${var/abc/\&amp; }
echo &quot;${var/abc/\&amp; }&quot;
echo ${var/abc/&quot;\&amp; &quot;}
echo ${var/abc/&quot;&amp; &quot;}
echo ${var/abc/&quot;$rep&quot;}
</pre></div>
<p>will display two lines of &quot;abc def&quot; and a third line of &quot;&amp; def&quot;.
The first two are replaced because the backslash is removed by quote
removal performed during the expansion of <var>string</var>
(the expansion is performed in a
context that doesn&rsquo;t take any enclosing double quotes into account, as
with other word expansions).
In the third case, the double quotes affect the expansion
of &lsquo;<samp>\&amp;</samp>&rsquo;, and, because &lsquo;<samp>&amp;</samp>&rsquo; is not one of the characters for
which backslash is special in double quotes,
the backslash survives the expansion, inhibits the replacement,
but is removed because it is treated specially.
One could use &lsquo;<samp>\\&amp;</samp>&rsquo;, unquoted, as the replacement string to achive
the same effect.
It should rarely be necessary to enclose only <var>string</var> in double
<p>will display four lines of &quot;&amp; def&quot;.
Like the pattern removal operators, double quotes surrounding the
replacement string quote the expanded characters, while double quotes
enclosing the entire parameter substitution do not, since
the expansion is performed in a
context that doesn&rsquo;t take any enclosing double quotes into account.
</p>
<p>Since backslash can escape &lsquo;<samp>&amp;</samp>&rsquo;, it can also escape a backslash in
the replacement string.
This means that &lsquo;<samp>\\</samp>&rsquo; will insert a literal
backslash into the replacement, so these two <code>echo</code> commands
</p>
<div class="example">
<pre class="example">var=abcdef
rep='\\&amp;xyz'
echo ${var/abc/\\&amp;xyz}
echo ${var/abc/$rep}
</pre></div>
<p>will both output &lsquo;<samp>\abcxyzdef</samp>&rsquo;.
</p>
<p>It should rarely be necessary to enclose only <var>string</var> in double
quotes.
</p>
<p>If the <code>nocasematch</code> shell option