enable support for using `&' in the pattern substitution replacement string

This commit is contained in:
Chet Ramey
2021-10-04 15:30:21 -04:00
parent 70d7c6430d
commit f188aa6a01
22 changed files with 518 additions and 209 deletions
+32 -15
View File
@@ -1827,17 +1827,32 @@ EEXXPPAANNSSIIOONN
turn, and the expansion is the resultant list.
${_p_a_r_a_m_e_t_e_r//_p_a_t_t_e_r_n//_s_t_r_i_n_g}
${_p_a_r_a_m_e_t_e_r////_p_a_t_t_e_r_n//_s_t_r_i_n_g}
${_p_a_r_a_m_e_t_e_r//##_p_a_t_t_e_r_n//_s_t_r_i_n_g}
${_p_a_r_a_m_e_t_e_r//%%_p_a_t_t_e_r_n//_s_t_r_i_n_g}
PPaatttteerrnn ssuubbssttiittuuttiioonn. The _p_a_t_t_e_r_n is expanded to produce a pat-
tern just as in pathname expansion, _P_a_r_a_m_e_t_e_r is expanded and
tern just as in pathname expansion. _P_a_r_a_m_e_t_e_r is expanded and
the longest match of _p_a_t_t_e_r_n against its value is replaced with
_s_t_r_i_n_g. The match is performed using the rules described under
PPaatttteerrnn MMaattcchhiinngg below. If _p_a_t_t_e_r_n begins with //, all matches
of _p_a_t_t_e_r_n are replaced with _s_t_r_i_n_g. Normally only the first
match is replaced. If _p_a_t_t_e_r_n begins with ##, it must match at
the beginning of the expanded value of _p_a_r_a_m_e_t_e_r. If _p_a_t_t_e_r_n
begins with %%, it must match at the end of the expanded value of
_p_a_r_a_m_e_t_e_r. If _s_t_r_i_n_g is null, matches of _p_a_t_t_e_r_n are deleted
and the // following _p_a_t_t_e_r_n may be omitted. If the nnooccaasseemmaattcchh
_s_t_r_i_n_g. _s_t_r_i_n_g undergoes tilde expansion, parameter and vari-
able expansion, arithmetic expansion, command and process sub-
stitution, and quote removal. The match is performed using the
rules described under PPaatttteerrnn MMaattcchhiinngg below. In the first form
above, only the first match is replaced. If there are two
slashes separating _p_a_r_a_m_e_t_e_r and _p_a_t_t_e_r_n (the second form
above), all matches of _p_a_t_t_e_r_n are replaced with _s_t_r_i_n_g. If
_p_a_t_t_e_r_n is preceded by ## (the third form above), it must match
at the beginning of the expanded value of _p_a_r_a_m_e_t_e_r. If _p_a_t_t_e_r_n
is preceded by %% (the fourth form above), it must match at the
end of the expanded value of _p_a_r_a_m_e_t_e_r. If the expansion of
_s_t_r_i_n_g is null, matches of _p_a_t_t_e_r_n are deleted. If _s_t_r_i_n_g is
null, matches of _p_a_t_t_e_r_n are deleted and the // following _p_a_t_t_e_r_n
may be omitted. Any unquoted instances of && in _s_t_r_i_n_g are re-
placed with the matching portion of _p_a_t_t_e_r_n. Backslash is used
to quote && in _s_t_r_i_n_g; users should take care if _s_t_r_i_n_g is dou-
ble-quoted to avoid unwanted interactions between the backslash
and double-quoting. Pattern substitution performs the check for
&& before expanding _s_t_r_i_n_g to catch backslashes escaping the &&
before they are removed by the expansion. If the nnooccaasseemmaattcchh
shell option is enabled, the match is performed without regard
to the case of alphabetic characters. If _p_a_r_a_m_e_t_e_r is @@ or **,
the substitution operation is applied to each positional parame-
@@ -2695,11 +2710,13 @@ SSIIMMPPLLEE CCOOMMMMAANNDD EEXXPPAANNSSIIOONN
able.
If no command name results, the variable assignments affect the current
shell environment. Otherwise, the variables are added to the environ-
ment of the executed command and do not affect the current shell envi-
ronment. If any of the assignments attempts to assign a value to a
readonly variable, an error occurs, and the command exits with a non-
zero status.
shell environment. In the case of such a command (one that consists
only of assignment statements and redirections), assignment statements
are performed before redirections. Otherwise, the variables are added
to the environment of the executed command and do not affect the cur-
rent shell environment. If any of the assignments attempts to assign a
value to a readonly variable, an error occurs, and the command exits
with a non-zero status.
If no command name results, redirections are performed, but do not af-
fect the current shell environment. A redirection error causes the
@@ -6517,4 +6534,4 @@ BBUUGGSS
GNU Bash 5.1 2021 August 23 BASH(1)
GNU Bash 5.1 2021 October 1 BASH(1)