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
+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