change to behavior of '&' in pattern substitution replacement string; fix for blank lines in multiline commands saved in command history

This commit is contained in:
Chet Ramey
2022-01-18 10:59:53 -05:00
parent 5e6f45d9b1
commit 2a1c81bf63
31 changed files with 1596 additions and 1312 deletions
+30 -20
View File
@@ -9,7 +9,7 @@ SSYYNNOOPPSSIISS
bbaasshh [options] [command_string | file]
CCOOPPYYRRIIGGHHTT
Bash is Copyright (C) 1989-2021 by the Free Software Foundation, Inc.
Bash is Copyright (C) 1989-2022 by the Free Software Foundation, Inc.
DDEESSCCRRIIPPTTIIOONN
BBaasshh is an sshh-compatible command language interpreter that executes
@@ -1849,24 +1849,34 @@ EEXXPPAANNSSIIOONN
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. If the ppaattssuubb__rreeppllaacceemmeenntt shell option is en-
abled using sshhoopptt, 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; the backslash is removed in order to per-
mit a literal && in the replacement string. Users should take
care if _s_t_r_i_n_g is double-quoted to avoid unwanted interactions
between the backslash and double-quoting. Pattern substitution
performs the check for && after expanding _s_t_r_i_n_g; shell program-
mers should quote backslashes intended to escape the && and in-
hibit replacement so they survive any quote removal performed by
the expansion of _s_t_r_i_n_g. If the nnooccaasseemmaattcchh shell option is en-
abled, the match is performed without regard to the case of al-
phabetic characters. If _p_a_r_a_m_e_t_e_r is @@ or **, the substitution
operation is applied to each positional parameter in turn, and
the expansion is the resultant list. If _p_a_r_a_m_e_t_e_r is an array
variable subscripted with @@ or **, the substitution operation is
applied to each member of the array in turn, and the expansion
is the resultant list.
may be omitted.
If the ppaattssuubb__rreeppllaacceemmeenntt shell option is enabled using sshhoopptt,
any unquoted instances of && in _s_t_r_i_n_g are replaced with the
matching portion of _p_a_t_t_e_r_n.
Quoting any part of _s_t_r_i_n_g inhibits replacement in the expansion
of the quoted portion, including replacement strings stored in
shell variables. Backslash will escape && in _s_t_r_i_n_g; the back-
slash is removed in order to permit a literal && in the replace-
ment string. Backslash can also be used to escape a backslash;
\\\\ results in a literal backslash in the replacement. Users
should take care if _s_t_r_i_n_g 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 && after expanding
_s_t_r_i_n_g; shell programmers should quote any occurrences of && they
want to be taken literally in the replacement and ensure any in-
stances of && they want to be replaced are unquoted.
If the nnooccaasseemmaattcchh shell option is enabled, the match is per-
formed 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 parameter in turn, and the expansion is the re-
sultant list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted
with @@ or **, the substitution operation is applied to each mem-
ber of the array in turn, and the expansion is the resultant
list.
${_p_a_r_a_m_e_t_e_r^^_p_a_t_t_e_r_n}
${_p_a_r_a_m_e_t_e_r^^^^_p_a_t_t_e_r_n}
@@ -6597,4 +6607,4 @@ BBUUGGSS
GNU Bash 5.2 2021 December 26 BASH(1)
GNU Bash 5.2 2022 January 17 BASH(1)
+21 -12
View File
@@ -5,12 +5,12 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Sun Dec 26 16:02:07 EST 2021
.\" Last Change: Mon Jan 17 17:27:05 EST 2022
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2021 December 26" "GNU Bash 5.2"
.TH BASH 1 "2022 January 17" "GNU Bash 5.2"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
@@ -50,8 +50,8 @@ bash \- GNU Bourne-Again SHell
[options]
[command_string | file]
.SH COPYRIGHT
.if n Bash is Copyright (C) 1989-2021 by the Free Software Foundation, Inc.
.if t Bash is Copyright \(co 1989-2021 by the Free Software Foundation, Inc.
.if n Bash is Copyright (C) 1989-2022 by the Free Software Foundation, Inc.
.if t Bash is Copyright \(co 1989-2022 by the Free Software Foundation, Inc.
.SH DESCRIPTION
.B Bash
is an \fBsh\fR-compatible command language interpreter that
@@ -3373,18 +3373,27 @@ matches of \fIpattern\fP are deleted.
If \fIstring\fP is null,
matches of \fIpattern\fP are deleted
and the \fB/\fP following \fIpattern\fP may be omitted.
.sp 1
If the \fBpatsub_replacement\fP shell option is enabled using \fBshopt\fP,
any unquoted instances of \fB&\fP in \fIstring\fP are replaced with the
matching portion of \fIpattern\fP.
Backslash is used to quote \fB&\fP in \fIstring\fP; the backslash is removed
.sp 1
Quoting any part of \fIstring\fP inhibits replacement in the
expansion of the quoted portion, including replacement strings stored
in shell variables.
Backslash will escape \fB&\fP in \fIstring\fP; the backslash is removed
in order to permit a literal \fB&\fP in the replacement string.
Users should take care
if \fIstring\fP is double-quoted to avoid unwanted interactions between
the backslash and double-quoting.
Pattern substitution performs the check for \fB&\fP after expanding
\fIstring\fP; shell programmers should quote backslashes intended to escape
the \fB&\fP and inhibit replacement so they survive any quote removal
performed by the expansion of \fIstring\fP.
Backslash can also be used to escape a backslash; \fB\e\e\fP results in
a literal backslash in the replacement.
Users should take care if \fIstring\fP 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 \fB&\fP after
expanding \fIstring\fP;
shell programmers should quote any occurrences of \fB&\fP
they want to be taken literally in the replacement
and ensure any instances of \fB&\fP they want to be replaced are unquoted.
.sp 1
If the
.B nocasematch
shell option is enabled, the match is performed without regard to the case
+178 -158
View File
@@ -2,9 +2,9 @@ This is bashref.info, produced by makeinfo version 6.8 from
bashref.texi.
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 26 December 2021).
Bash shell (version 5.2, 17 January 2022).
This is Edition 5.2, last updated 26 December 2021, of 'The GNU Bash
This is Edition 5.2, last updated 17 January 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Copyright (C) 1988-2021 Free Software Foundation, Inc.
@@ -27,10 +27,10 @@ Bash Features
*************
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 26 December 2021). The Bash home page is
Bash shell (version 5.2, 17 January 2022). The Bash home page is
<http://www.gnu.org/software/bash/>.
This is Edition 5.2, last updated 26 December 2021, of 'The GNU Bash
This is Edition 5.2, last updated 17 January 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Bash contains features that appear in other popular shells, and some
@@ -2079,38 +2079,58 @@ omitted, the operator tests only for existence.
If the 'patsub_replacement' shell option is enabled using 'shopt',
any unquoted instances of '&' in STRING are replaced with the
matching portion of PATTERN. This is intended to duplicate a
common 'sed' idiom. Backslash is used to quote '&' in STRING; the
backslash is removed in order to permit a literal '&' in the
replacement string. Pattern substitution performs the check for
'&' after expanding STRING, so users should take care to quote
backslashes intended to escape the '&' and inhibit replacement so
they survive any quote removal performed by the expansion of
STRING. For instance,
common 'sed' idiom.
Quoting any part of STRING inhibits replacement in the expansion of
the quoted portion, including replacement strings stored in shell
variables. Backslash will escape '&' in STRING; the backslash is
removed in order to permit a literal '&' in the replacement string.
Users should take care if STRING 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 '&' after expanding
STRING, so users should ensure to properly quote any occurrences of
'&' they want to be taken literally in the replacement and ensure
any instances of '&' they want to be replaced are unquoted.
For instance,
var=abcdef
rep='& '
echo ${var/abc/& }
echo "${var/abc/& }"
echo ${var/abc/"& "}
echo ${var/abc/$rep}
echo "${var/abc/$rep}"
will display three lines of "abc def", while
will display four lines of "abc def", while
var=abcdef
rep='& '
echo ${var/abc/\& }
echo "${var/abc/\& }"
echo ${var/abc/"\& "}
echo ${var/abc/"& "}
echo ${var/abc/"$rep"}
will display two lines of "abc def" and a third line of "& def".
The first two are replaced because the backslash is removed by
quote removal performed during the expansion of STRING (the
expansion is performed in a context that doesn't take any enclosing
double quotes into account, as with other word expansions). In the
third case, the double quotes affect the expansion of '\&', and,
because '&' 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 '\\&', unquoted, as the replacement
string to achive the same effect. It should rarely be necessary to
enclose only STRING in double quotes.
will display four lines of "& def". 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't take any enclosing double quotes into
account.
Since backslash can escape '&', it can also escape a backslash in
the replacement string. This means that '\\' will insert a literal
backslash into the replacement, so these two 'echo' commands
var=abcdef
rep='\\&xyz'
echo ${var/abc/\\&xyz}
echo ${var/abc/$rep}
will both output '\abcxyzdef'.
It should rarely be necessary to enclose only STRING in double
quotes.
If the 'nocasematch' shell option (see the description of 'shopt'
in *note The Shopt Builtin::) is enabled, the match is performed
@@ -12423,138 +12443,138 @@ D.5 Concept Index

Tag Table:
Node: Top897
Node: Introduction2817
Node: What is Bash?3033
Node: What is a shell?4147
Node: Definitions6685
Node: Basic Shell Features9636
Node: Shell Syntax10855
Node: Shell Operation11881
Node: Quoting13174
Node: Escape Character14478
Node: Single Quotes14963
Node: Double Quotes15311
Node: ANSI-C Quoting16589
Node: Locale Translation17899
Node: Creating Internationalized Scripts19210
Node: Comments23327
Node: Shell Commands23945
Node: Reserved Words24883
Node: Simple Commands25639
Node: Pipelines26293
Node: Lists29252
Node: Compound Commands31047
Node: Looping Constructs32059
Node: Conditional Constructs34554
Node: Command Grouping48898
Node: Coprocesses50376
Node: GNU Parallel53039
Node: Shell Functions53956
Node: Shell Parameters61247
Node: Positional Parameters65635
Node: Special Parameters66537
Node: Shell Expansions69751
Node: Brace Expansion71878
Node: Tilde Expansion74612
Node: Shell Parameter Expansion77233
Node: Command Substitution95099
Node: Arithmetic Expansion96454
Node: Process Substitution97422
Node: Word Splitting98542
Node: Filename Expansion100486
Node: Pattern Matching103235
Node: Quote Removal107843
Node: Redirections108138
Node: Executing Commands117798
Node: Simple Command Expansion118468
Node: Command Search and Execution120578
Node: Command Execution Environment122956
Node: Environment125991
Node: Exit Status127654
Node: Signals129438
Node: Shell Scripts132887
Node: Shell Builtin Commands135914
Node: Bourne Shell Builtins137952
Node: Bash Builtins159413
Node: Modifying Shell Behavior190269
Node: The Set Builtin190614
Node: The Shopt Builtin201215
Node: Special Builtins217127
Node: Shell Variables218106
Node: Bourne Shell Variables218543
Node: Bash Variables220647
Node: Bash Features253463
Node: Invoking Bash254476
Node: Bash Startup Files260489
Node: Interactive Shells265592
Node: What is an Interactive Shell?266002
Node: Is this Shell Interactive?266651
Node: Interactive Shell Behavior267466
Node: Bash Conditional Expressions271095
Node: Shell Arithmetic275737
Node: Aliases278681
Node: Arrays281294
Node: The Directory Stack287541
Node: Directory Stack Builtins288325
Node: Controlling the Prompt292585
Node: The Restricted Shell295550
Node: Bash POSIX Mode298160
Node: Shell Compatibility Mode309433
Node: Job Control317462
Node: Job Control Basics317922
Node: Job Control Builtins322924
Node: Job Control Variables328324
Node: Command Line Editing329480
Node: Introduction and Notation331151
Node: Readline Interaction332774
Node: Readline Bare Essentials333965
Node: Readline Movement Commands335748
Node: Readline Killing Commands336708
Node: Readline Arguments338626
Node: Searching339670
Node: Readline Init File341856
Node: Readline Init File Syntax343117
Node: Conditional Init Constructs364605
Node: Sample Init File368801
Node: Bindable Readline Commands371925
Node: Commands For Moving373129
Node: Commands For History375180
Node: Commands For Text380174
Node: Commands For Killing383823
Node: Numeric Arguments386856
Node: Commands For Completion387995
Node: Keyboard Macros392186
Node: Miscellaneous Commands392873
Node: Readline vi Mode398812
Node: Programmable Completion399719
Node: Programmable Completion Builtins407499
Node: A Programmable Completion Example418194
Node: Using History Interactively423441
Node: Bash History Facilities424125
Node: Bash History Builtins427130
Node: History Interaction432138
Node: Event Designators435758
Node: Word Designators437112
Node: Modifiers438872
Node: Installing Bash440683
Node: Basic Installation441820
Node: Compilers and Options445542
Node: Compiling For Multiple Architectures446283
Node: Installation Names447976
Node: Specifying the System Type450085
Node: Sharing Defaults450801
Node: Operation Controls451474
Node: Optional Features452432
Node: Reporting Bugs463650
Node: Major Differences From The Bourne Shell464925
Node: GNU Free Documentation License481775
Node: Indexes506952
Node: Builtin Index507406
Node: Reserved Word Index514233
Node: Variable Index516681
Node: Function Index533173
Node: Concept Index546957
Node: Top895
Node: Introduction2813
Node: What is Bash?3029
Node: What is a shell?4143
Node: Definitions6681
Node: Basic Shell Features9632
Node: Shell Syntax10851
Node: Shell Operation11877
Node: Quoting13170
Node: Escape Character14474
Node: Single Quotes14959
Node: Double Quotes15307
Node: ANSI-C Quoting16585
Node: Locale Translation17895
Node: Creating Internationalized Scripts19206
Node: Comments23323
Node: Shell Commands23941
Node: Reserved Words24879
Node: Simple Commands25635
Node: Pipelines26289
Node: Lists29248
Node: Compound Commands31043
Node: Looping Constructs32055
Node: Conditional Constructs34550
Node: Command Grouping48894
Node: Coprocesses50372
Node: GNU Parallel53035
Node: Shell Functions53952
Node: Shell Parameters61243
Node: Positional Parameters65631
Node: Special Parameters66533
Node: Shell Expansions69747
Node: Brace Expansion71874
Node: Tilde Expansion74608
Node: Shell Parameter Expansion77229
Node: Command Substitution95566
Node: Arithmetic Expansion96921
Node: Process Substitution97889
Node: Word Splitting99009
Node: Filename Expansion100953
Node: Pattern Matching103702
Node: Quote Removal108310
Node: Redirections108605
Node: Executing Commands118265
Node: Simple Command Expansion118935
Node: Command Search and Execution121045
Node: Command Execution Environment123423
Node: Environment126458
Node: Exit Status128121
Node: Signals129905
Node: Shell Scripts133354
Node: Shell Builtin Commands136381
Node: Bourne Shell Builtins138419
Node: Bash Builtins159880
Node: Modifying Shell Behavior190736
Node: The Set Builtin191081
Node: The Shopt Builtin201682
Node: Special Builtins217594
Node: Shell Variables218573
Node: Bourne Shell Variables219010
Node: Bash Variables221114
Node: Bash Features253930
Node: Invoking Bash254943
Node: Bash Startup Files260956
Node: Interactive Shells266059
Node: What is an Interactive Shell?266469
Node: Is this Shell Interactive?267118
Node: Interactive Shell Behavior267933
Node: Bash Conditional Expressions271562
Node: Shell Arithmetic276204
Node: Aliases279148
Node: Arrays281761
Node: The Directory Stack288008
Node: Directory Stack Builtins288792
Node: Controlling the Prompt293052
Node: The Restricted Shell296017
Node: Bash POSIX Mode298627
Node: Shell Compatibility Mode309900
Node: Job Control317929
Node: Job Control Basics318389
Node: Job Control Builtins323391
Node: Job Control Variables328791
Node: Command Line Editing329947
Node: Introduction and Notation331618
Node: Readline Interaction333241
Node: Readline Bare Essentials334432
Node: Readline Movement Commands336215
Node: Readline Killing Commands337175
Node: Readline Arguments339093
Node: Searching340137
Node: Readline Init File342323
Node: Readline Init File Syntax343584
Node: Conditional Init Constructs365072
Node: Sample Init File369268
Node: Bindable Readline Commands372392
Node: Commands For Moving373596
Node: Commands For History375647
Node: Commands For Text380641
Node: Commands For Killing384290
Node: Numeric Arguments387323
Node: Commands For Completion388462
Node: Keyboard Macros392653
Node: Miscellaneous Commands393340
Node: Readline vi Mode399279
Node: Programmable Completion400186
Node: Programmable Completion Builtins407966
Node: A Programmable Completion Example418661
Node: Using History Interactively423908
Node: Bash History Facilities424592
Node: Bash History Builtins427597
Node: History Interaction432605
Node: Event Designators436225
Node: Word Designators437579
Node: Modifiers439339
Node: Installing Bash441150
Node: Basic Installation442287
Node: Compilers and Options446009
Node: Compiling For Multiple Architectures446750
Node: Installation Names448443
Node: Specifying the System Type450552
Node: Sharing Defaults451268
Node: Operation Controls451941
Node: Optional Features452899
Node: Reporting Bugs464117
Node: Major Differences From The Bourne Shell465392
Node: GNU Free Documentation License482242
Node: Indexes507419
Node: Builtin Index507873
Node: Reserved Word Index514700
Node: Variable Index517148
Node: Function Index533640
Node: Concept Index547424

End Tag Table
+43 -22
View File
@@ -2444,46 +2444,67 @@ If the @code{patsub_replacement} shell option is enabled using @code{shopt},
any unquoted instances of @samp{&} in @var{string} are replaced with the
matching portion of @var{pattern}.
This is intended to duplicate a common @code{sed} idiom.
Backslash is used to quote @samp{&} in @var{string}; the backslash is removed
Quoting any part of @var{string} inhibits replacement in the
expansion of the quoted portion, including replacement strings stored
in shell variables.
Backslash will escape @samp{&} in @var{string}; the backslash is removed
in order to permit a literal @samp{&} in the replacement string.
Pattern substitution performs the check for @samp{&} after expanding
@var{string},
so users should take care to quote backslashes intended to escape
the @samp{&} and inhibit replacement so they survive any quote removal
performed by the expansion of @var{string}.
Users should take care if @var{string} 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 @samp{&} after
expanding @var{string},
so users should ensure to properly quote any occurrences of @samp{&}
they want to be taken literally in the replacement
and ensure any instances of @samp{&} they want to be replaced are unquoted.
For instance,
@example
var=abcdef
rep='& '
echo $@{var/abc/& @}
echo "$@{var/abc/& @}"
echo $@{var/abc/"& "@}
echo $@{var/abc/$rep@}
echo "$@{var/abc/$rep@}"
@end example
@noindent
will display three lines of "abc def", while
will display four lines of "abc def", while
@example
var=abcdef
rep='& '
echo $@{var/abc/\& @}
echo "$@{var/abc/\& @}"
echo $@{var/abc/"\& "@}
echo $@{var/abc/"& "@}
echo $@{var/abc/"$rep"@}
@end example
@noindent
will display two lines of "abc def" and a third line of "& def".
The first two are replaced because the backslash is removed by quote
removal performed during the expansion of @var{string}
(the expansion is performed in a
context that doesn't take any enclosing double quotes into account, as
with other word expansions).
In the third case, the double quotes affect the expansion
of @samp{\&}, and, because @samp{&} 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 @samp{\\&}, unquoted, as the replacement string to achive
the same effect.
will display four lines of "& def".
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't take any enclosing double quotes into account.
Since backslash can escape @samp{&}, it can also escape a backslash in
the replacement string.
This means that @samp{\\} will insert a literal
backslash into the replacement, so these two @code{echo} commands
@example
var=abcdef
rep='\\&xyz'
echo $@{var/abc/\\&xyz@}
echo $@{var/abc/$rep@}
@end example
@noindent
will both output @samp{\abcxyzdef}.
It should rarely be necessary to enclose only @var{string} in double
quotes.
+4 -4
View File
@@ -1,11 +1,11 @@
@ignore
Copyright (C) 1988-2021 Free Software Foundation, Inc.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Sun Dec 26 16:02:48 EST 2021
@set LASTCHANGE Mon Jan 17 17:03:25 EST 2022
@set EDITION 5.2
@set VERSION 5.2
@set UPDATED 26 December 2021
@set UPDATED-MONTH December 2021
@set UPDATED 17 January 2022
@set UPDATED-MONTH January 2022