new option to auto-close varassign redirs; fixed some new parser error reporting issues

This commit is contained in:
Chet Ramey
2021-06-28 10:26:43 -04:00
parent 03de84de4a
commit 3fb16fce32
19 changed files with 2507 additions and 2373 deletions
+41
View File
@@ -10603,3 +10603,44 @@ builtins/evalstring.c
command, rewind the input string here before returning, instead of
guessing where to rewind it in the caller
6/22
----
redir.c
- do_redirection_internal: if VARASSIGN_REDIR_AUTOCLOSE is non-zero,
add a redirect to automatically close {var}<fn and other styles of
varassign redirection. It's zero by default
builtins/shopt.def
- varredir_close: new shell option, mirrors the value of
varassign_redir_autoclose. Suggested multiple times by multiple
people
doc/{bash.1,bashref.texi}
- varredir_close: document new shell option (the name is tentative)
6/24
----
parse.y
- yylex: if read_token returns a value < 0, return YYerror to the
parser
- parse_comsub: if the current_token is not shell_eof_token when
yyparse returns, return an error to read_token_word instead of
trying to keep parsing. Fixes interactive-only (?) bug reported by
Koichi Murase <myoga.murase@gmail.com>
parser.h
- PST_NOERROR: don't print error messages in yyerror(), just reset
the parser and return
parse.y
- yyerror: if parser_state & PST_NOERROR, don't print an error message
- xparse_dolparen: if the flags includes SX_COMPLETE, add PST_NOERROR
to parser_state, to inhibit error messages. Fixes bug with adding
lines with incomplete command substitutions to the history list
reported by Koichi Murase <myoga.murase@gmail.com>
subst.c
- skip_matched_pair: make sure to pass the SX_COMPLETE flag to
extract_delimited_string
+1
View File
@@ -1509,6 +1509,7 @@ tests/vredir4.sub f
tests/vredir5.sub f
tests/vredir6.sub f
tests/vredir7.sub f
tests/vredir8.sub f
tests/misc/dev-tcp.tests f
tests/misc/perf-script f
tests/misc/perftest f
+3
View File
@@ -93,6 +93,7 @@ extern int lastpipe_opt;
extern int inherit_errexit;
extern int localvar_inherit;
extern int localvar_unset;
extern int varassign_redir_autoclose;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
@@ -249,6 +250,7 @@ static struct {
#if defined (SYSLOG_HISTORY) && defined (SYSLOG_SHOPT)
{ "syslog_history", &syslog_history, (shopt_set_func_t *)NULL },
#endif
{ "varredir_close", &varassign_redir_autoclose, (shopt_set_func_t *)NULL },
{ "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL },
{ (char *)0, (int *)0, (shopt_set_func_t *)NULL }
};
@@ -357,6 +359,7 @@ reset_shopt_options ()
glob_ignore_case = match_ignore_case = 0;
print_shift_error = 0;
source_uses_path = promptvars = 1;
varassign_redir_autoclose = 0;
#if defined (JOB_CONTROL)
check_jobs_at_exit = 0;
+2211 -2196
View File
File diff suppressed because it is too large Load Diff
+25 -16
View File
@@ -589,12 +589,12 @@ The
variable may be used to specify the format of
the time information.
.PP
Each command in a pipeline is executed as a separate process (i.e., in a
subshell).
Each command in a pipeline is executed in a \fIsubshell\fP, which is a
separate process.
See
.SM
\fBCOMMAND EXECUTION ENVIRONMENT\fP
for a description of a subshell environment.
for a description of subshells and a subshell environment.
If the \fBlastpipe\fP option is enabled using the \fBshopt\fP builtin
(see the description of \fBshopt\fP below),
the last element of a pipeline may be run by the shell process
@@ -673,10 +673,10 @@ the rest of the command by one or more newlines, and may be followed by a
newline in place of a semicolon.
.TP
(\fIlist\fP)
\fIlist\fP is executed in a subshell environment (see
\fIlist\fP is executed in a subshell (see
.SM
\fBCOMMAND EXECUTION ENVIRONMENT\fP
below).
below for a description of a subshell environment).
Variable assignments and builtin
commands that affect the shell's environment do not remain in effect
after the command completes. The return status is the exit status of
@@ -1278,10 +1278,7 @@ is evaluated as an arithmetic expression even if the $((...)) expansion is
not used (see
.B "Arithmetic Expansion"
below).
Word splitting is not performed, with the exception
of \fB"$@"\fP as explained below under
.BR "Special Parameters" .
Pathname expansion is not performed.
Word splitting and pathname expansion are not performed.
Assignment statements may also appear as arguments to the
.BR alias ,
.BR declare ,
@@ -1435,7 +1432,7 @@ builtin command, or those set by the shell itself
option).
.TP
.B $
Expands to the process ID of the shell. In a () subshell, it
Expands to the process ID of the shell. In a subshell, it
expands to the process ID of the current shell, not the
subshell.
.TP
@@ -3950,7 +3947,8 @@ by {\fIvarname\fP}, the value of \fIvarname\fP defines the file
descriptor to close.
If {\fIvarname\fP} is supplied, the redirection persists beyond
the scope of the command, allowing the shell programmer to manage
the file descriptor himself.
the file descriptor's lifetime manually.
The \fBvarredir_close\fP shell option manages this behavior.
.PP
In the following descriptions, if the file descriptor number is
omitted, and the first character of the redirection operator is
@@ -4503,7 +4501,8 @@ or
will list the function names only
(and optionally the source file and line number, if the \fBextdebug\fP
shell option is enabled).
Functions may be exported so that subshells
Functions may be exported so that child shell processes
(those created when executing a separate shell invocation)
automatically have them defined with the
.B \-f
option to the
@@ -4892,8 +4891,9 @@ to the command are set to the arguments given, if any.
If this execution fails because the file is not in executable
format, and the file is not a directory, it is assumed to be
a \fIshell script\fP, a file
containing shell commands. A subshell is spawned to execute
it. This subshell reinitializes itself, so
containing shell commands, and the shell creates a
to execute it.
This subshell reinitializes itself, so
that the effect is as if a new shell had been invoked
to handle the script, with the exception that the locations of
commands remembered by the parent (see
@@ -4949,8 +4949,8 @@ of \fB$$\fP, and the value of
When a simple command other than a builtin or shell function
is to be executed, it
is invoked in a separate execution environment that consists of
the following. Unless otherwise noted, the values are inherited
from the shell.
the following.
Unless otherwise noted, the values are inherited from the shell.
.if n .sp 1
.IP \(bu
the shell's open files, plus any modifications and additions specified
@@ -4969,6 +4969,8 @@ shell's parent, and traps ignored by the shell are ignored
A command invoked in this separate environment cannot affect the
shell's execution environment.
.PP
A \fIsubshell\fP is a copy of the shell process.
.PP
Command substitution, commands grouped with parentheses,
and asynchronous commands are invoked in a
subshell environment that is a duplicate of the shell environment,
@@ -10398,6 +10400,13 @@ If set, the
to find the directory containing the file supplied as an argument.
This option is enabled by default.
.TP 8
.B varredir_close
If set, the shell automatically closes file descriptors assigned using the
\fI{varname}\fP redirection syntax (see
.SM
.B REDIRECTION
above) instead of leaving them open when the command completes.
.TP 8
.B xpg_echo
If set, the \fBecho\fP builtin expands backslash-escape sequences
by default.
+145 -128
View File
@@ -703,8 +703,8 @@ information.
If the pipeline is not executed asynchronously (*note Lists::), the
shell waits for all commands in the pipeline to complete.
Each command in a pipeline is executed in its own subshell, which is
a separate process (*note Command Execution Environment::). If the
Each command in a pipeline is executed in its own "subshell", which
is a separate process (*note Command Execution Environment::). If the
'lastpipe' option is enabled using the 'shopt' builtin (*note The Shopt
Builtin::), the last element of a pipeline may be run by the shell
process when job control is not active.
@@ -1176,9 +1176,9 @@ list may be redirected to a single stream.
'()'
( LIST )
Placing a list of commands between parentheses causes a subshell
environment to be created (*note Command Execution Environment::),
and each of the commands in LIST to be executed in that subshell.
Placing a list of commands between parentheses forces the shell to
create a subshell (*note Command Execution Environment::), and each
of the commands in LIST is executed in that subshell environment.
Since the LIST is executed in a subshell, variable assignments do
not remain in effect after the subshell completes.
@@ -1423,7 +1423,8 @@ been shadowed will become visible.
the 'declare' ('typeset') builtin command (*note Bash Builtins::). The
'-F' option to 'declare' or 'typeset' will list the function names only
(and optionally the source file and line number, if the 'extdebug' shell
option is enabled). Functions may be exported so that subshells
option is enabled). Functions may be exported so that child shell
processes (those created when executing a separate shell invocation)
automatically have them defined with the '-f' option to the 'export'
builtin (*note Bourne Shell Builtins::).
@@ -1584,9 +1585,8 @@ only be referenced; assignment to them is not allowed.
shell itself (such as the '-i' option).
'$'
($$) Expands to the process ID of the shell. In a '()' subshell,
it expands to the process ID of the invoking shell, not the
subshell.
($$) Expands to the process ID of the shell. In a subshell, it
expands to the process ID of the invoking shell, not the subshell.
'!'
($!) Expands to the process ID of the job most recently placed
@@ -2382,6 +2382,14 @@ the following sub-patterns:
'!(PATTERN-LIST)'
Matches anything except one of the given patterns.
When matching filenames, the 'dotglob' shell option determines the
set of filenames that are tested: when 'dotglob' is enabled, the set of
filenames includes all files beginning with '.', but the filenames '.'
and '..' must be matched by a pattern or sub-pattern that begins with a
dot; when it is disabled, the set does not include any filenames
beginning with "." unless the pattern or sub-pattern begins with a '.'.
As above, '.' only has a special meaning when matching filenames.
Complicated extended pattern matching against long strings is slow,
especially when the patterns contain alternations and the strings
contain multiple matches. Using separate matches against shorter
@@ -2421,7 +2429,8 @@ file descriptor greater than 10 and assign it to {VARNAME}. If >&- or
<&- is preceded by {VARNAME}, the value of VARNAME defines the file
descriptor to close. If {VARNAME} is supplied, the redirection persists
beyond the scope of the command, allowing the shell programmer to manage
the file descriptor's lifetime manually.
the file descriptor's lifetime manually. The 'varredir_close' shell
option manages this behavior (*note The Shopt Builtin::).
In the following descriptions, if the file descriptor number is
omitted, and the first character of the redirection operator is '<', the
@@ -2805,6 +2814,8 @@ inherited from the shell.
A command invoked in this separate environment cannot affect the
shell's execution environment.
A "subshell" is a copy of the shell process.
Command substitution, commands grouped with parentheses, and
asynchronous commands are invoked in a subshell environment that is a
duplicate of the shell environment, except that traps caught by the
@@ -2960,8 +2971,8 @@ parameters are unset.
A shell script may be made executable by using the 'chmod' command to
turn on the execute bit. When Bash finds such a file while searching
the '$PATH' for a command, it spawns a subshell to execute it. In other
words, executing
the '$PATH' for a command, it creates a subshell to execute it. In
other words, executing
filename ARGUMENTS
is equivalent to executing
bash filename ARGUMENTS
@@ -4871,6 +4882,12 @@ This builtin allows you to change additional shell optional behavior.
find the directory containing the file supplied as an
argument. This option is enabled by default.
'varredir_close'
If set, the shell automatically closes file descriptors
assigned using the '{varname}' redirection syntax (*note
Redirections::) instead of leaving them open when the command
completes.
'xpg_echo'
If set, the 'echo' builtin expands backslash-escape sequences
by default.
@@ -11590,21 +11607,21 @@ D.3 Parameter and Variable Index
[index]
* Menu:
* !: Special Parameters. (line 56)
* !: Special Parameters. (line 55)
* #: Special Parameters. (line 39)
* $: Special Parameters. (line 51)
* $!: Special Parameters. (line 57)
* $!: Special Parameters. (line 56)
* $#: Special Parameters. (line 40)
* $$: Special Parameters. (line 52)
* $*: Special Parameters. (line 10)
* $-: Special Parameters. (line 47)
* $0: Special Parameters. (line 62)
* $0: Special Parameters. (line 61)
* $?: Special Parameters. (line 43)
* $@: Special Parameters. (line 23)
* $_: Bash Variables. (line 14)
* *: Special Parameters. (line 9)
* -: Special Parameters. (line 46)
* 0: Special Parameters. (line 61)
* 0: Special Parameters. (line 60)
* ?: Special Parameters. (line 42)
* @: Special Parameters. (line 22)
* _: Bash Variables. (line 13)
@@ -12215,118 +12232,118 @@ Node: Shell Commands23773
Node: Reserved Words24711
Node: Simple Commands25467
Node: Pipelines26121
Node: Lists29078
Node: Compound Commands30873
Node: Looping Constructs31885
Node: Conditional Constructs34380
Node: Command Grouping48670
Node: Coprocesses50145
Node: GNU Parallel52808
Node: Shell Functions53725
Node: Shell Parameters60945
Node: Positional Parameters65396
Node: Special Parameters66298
Node: Shell Expansions69522
Node: Brace Expansion71649
Node: Tilde Expansion74383
Node: Shell Parameter Expansion77004
Node: Command Substitution92133
Node: Arithmetic Expansion93488
Node: Process Substitution94420
Node: Word Splitting95540
Node: Filename Expansion97484
Node: Pattern Matching100084
Node: Quote Removal104202
Node: Redirections104497
Node: Executing Commands114071
Node: Simple Command Expansion114741
Node: Command Search and Execution116695
Node: Command Execution Environment119073
Node: Environment122059
Node: Exit Status123722
Node: Signals125506
Node: Shell Scripts127473
Node: Shell Builtin Commands130485
Node: Bourne Shell Builtins132523
Node: Bash Builtins153984
Node: Modifying Shell Behavior184498
Node: The Set Builtin184843
Node: The Shopt Builtin195256
Node: Special Builtins210217
Node: Shell Variables211196
Node: Bourne Shell Variables211633
Node: Bash Variables213737
Node: Bash Features246552
Node: Invoking Bash247565
Node: Bash Startup Files253578
Node: Interactive Shells258681
Node: What is an Interactive Shell?259091
Node: Is this Shell Interactive?259740
Node: Interactive Shell Behavior260555
Node: Bash Conditional Expressions264068
Node: Shell Arithmetic268710
Node: Aliases271654
Node: Arrays274267
Node: The Directory Stack280276
Node: Directory Stack Builtins281060
Node: Controlling the Prompt285320
Node: The Restricted Shell288285
Node: Bash POSIX Mode290882
Node: Shell Compatibility Mode302155
Node: Job Control308811
Node: Job Control Basics309271
Node: Job Control Builtins314273
Node: Job Control Variables319673
Node: Command Line Editing320829
Node: Introduction and Notation322500
Node: Readline Interaction324123
Node: Readline Bare Essentials325314
Node: Readline Movement Commands327097
Node: Readline Killing Commands328057
Node: Readline Arguments329975
Node: Searching331019
Node: Readline Init File333205
Node: Readline Init File Syntax334466
Node: Conditional Init Constructs355746
Node: Sample Init File359942
Node: Bindable Readline Commands363066
Node: Commands For Moving364270
Node: Commands For History366321
Node: Commands For Text371315
Node: Commands For Killing374964
Node: Numeric Arguments377997
Node: Commands For Completion379136
Node: Keyboard Macros383327
Node: Miscellaneous Commands384014
Node: Readline vi Mode389953
Node: Programmable Completion390860
Node: Programmable Completion Builtins398640
Node: A Programmable Completion Example409335
Node: Using History Interactively414582
Node: Bash History Facilities415266
Node: Bash History Builtins418271
Node: History Interaction423279
Node: Event Designators426899
Node: Word Designators428253
Node: Modifiers430013
Node: Installing Bash431824
Node: Basic Installation432961
Node: Compilers and Options436219
Node: Compiling For Multiple Architectures436960
Node: Installation Names438653
Node: Specifying the System Type439471
Node: Sharing Defaults440187
Node: Operation Controls440860
Node: Optional Features441818
Node: Reporting Bugs452618
Node: Major Differences From The Bourne Shell453893
Node: GNU Free Documentation License470743
Node: Indexes495920
Node: Builtin Index496374
Node: Reserved Word Index503201
Node: Variable Index505649
Node: Function Index522141
Node: Concept Index535925
Node: Lists29080
Node: Compound Commands30875
Node: Looping Constructs31887
Node: Conditional Constructs34382
Node: Command Grouping48672
Node: Coprocesses50150
Node: GNU Parallel52813
Node: Shell Functions53730
Node: Shell Parameters61021
Node: Positional Parameters65472
Node: Special Parameters66374
Node: Shell Expansions69588
Node: Brace Expansion71715
Node: Tilde Expansion74449
Node: Shell Parameter Expansion77070
Node: Command Substitution92199
Node: Arithmetic Expansion93554
Node: Process Substitution94486
Node: Word Splitting95606
Node: Filename Expansion97550
Node: Pattern Matching100150
Node: Quote Removal104758
Node: Redirections105053
Node: Executing Commands114713
Node: Simple Command Expansion115383
Node: Command Search and Execution117337
Node: Command Execution Environment119715
Node: Environment122750
Node: Exit Status124413
Node: Signals126197
Node: Shell Scripts128164
Node: Shell Builtin Commands131177
Node: Bourne Shell Builtins133215
Node: Bash Builtins154676
Node: Modifying Shell Behavior185190
Node: The Set Builtin185535
Node: The Shopt Builtin195948
Node: Special Builtins211158
Node: Shell Variables212137
Node: Bourne Shell Variables212574
Node: Bash Variables214678
Node: Bash Features247493
Node: Invoking Bash248506
Node: Bash Startup Files254519
Node: Interactive Shells259622
Node: What is an Interactive Shell?260032
Node: Is this Shell Interactive?260681
Node: Interactive Shell Behavior261496
Node: Bash Conditional Expressions265009
Node: Shell Arithmetic269651
Node: Aliases272595
Node: Arrays275208
Node: The Directory Stack281217
Node: Directory Stack Builtins282001
Node: Controlling the Prompt286261
Node: The Restricted Shell289226
Node: Bash POSIX Mode291823
Node: Shell Compatibility Mode303096
Node: Job Control309752
Node: Job Control Basics310212
Node: Job Control Builtins315214
Node: Job Control Variables320614
Node: Command Line Editing321770
Node: Introduction and Notation323441
Node: Readline Interaction325064
Node: Readline Bare Essentials326255
Node: Readline Movement Commands328038
Node: Readline Killing Commands328998
Node: Readline Arguments330916
Node: Searching331960
Node: Readline Init File334146
Node: Readline Init File Syntax335407
Node: Conditional Init Constructs356687
Node: Sample Init File360883
Node: Bindable Readline Commands364007
Node: Commands For Moving365211
Node: Commands For History367262
Node: Commands For Text372256
Node: Commands For Killing375905
Node: Numeric Arguments378938
Node: Commands For Completion380077
Node: Keyboard Macros384268
Node: Miscellaneous Commands384955
Node: Readline vi Mode390894
Node: Programmable Completion391801
Node: Programmable Completion Builtins399581
Node: A Programmable Completion Example410276
Node: Using History Interactively415523
Node: Bash History Facilities416207
Node: Bash History Builtins419212
Node: History Interaction424220
Node: Event Designators427840
Node: Word Designators429194
Node: Modifiers430954
Node: Installing Bash432765
Node: Basic Installation433902
Node: Compilers and Options437160
Node: Compiling For Multiple Architectures437901
Node: Installation Names439594
Node: Specifying the System Type440412
Node: Sharing Defaults441128
Node: Operation Controls441801
Node: Optional Features442759
Node: Reporting Bugs453559
Node: Major Differences From The Bourne Shell454834
Node: GNU Free Documentation License471684
Node: Indexes496861
Node: Builtin Index497315
Node: Reserved Word Index504142
Node: Variable Index506590
Node: Function Index523082
Node: Concept Index536866

End Tag Table
+20 -12
View File
@@ -798,7 +798,7 @@ the time information.
If the pipeline is not executed asynchronously (@pxref{Lists}), the
shell waits for all commands in the pipeline to complete.
Each command in a pipeline is executed in its own subshell, which is a
Each command in a pipeline is executed in its own @dfn{subshell}, which is a
separate process (@pxref{Command Execution Environment}).
If the @code{lastpipe} option is enabled using the @code{shopt} builtin
(@pxref{The Shopt Builtin}),
@@ -1368,11 +1368,11 @@ commands in the list may be redirected to a single stream.
( @var{list} )
@end example
Placing a list of commands between parentheses causes a subshell
environment to be created (@pxref{Command Execution Environment}), and each
of the commands in @var{list} to be executed in that subshell. Since the
@var{list} is executed in a subshell, variable assignments do not remain in
effect after the subshell completes.
Placing a list of commands between parentheses forces the shell to create
a subshell (@pxref{Command Execution Environment}), and each
of the commands in @var{list} is executed in that subshell environment.
Since the @var{list} is executed in a subshell, variable assignments do not
remain in effect after the subshell completes.
@item @{@}
@rwindex @{
@@ -1665,7 +1665,8 @@ The @option{-F} option to @code{declare} or @code{typeset}
will list the function names only
(and optionally the source file and line number, if the @code{extdebug}
shell option is enabled).
Functions may be exported so that subshells
Functions may be exported so that child shell processes
(those created when executing a separate shell invocation)
automatically have them defined with the
@option{-f} option to the @code{export} builtin
(@pxref{Bourne Shell Builtins}).
@@ -1712,9 +1713,7 @@ If the variable has its @code{integer}
attribute set, then @var{value}
is evaluated as an arithmetic expression even if the @code{$((@dots{}))}
expansion is not used (@pxref{Arithmetic Expansion}).
Word splitting is not performed, with the exception
of @code{"$@@"} as explained below.
Filename expansion is not performed.
Word splitting and filename expansion are not performed.
Assignment statements may also appear as arguments to the
@code{alias},
@code{declare}, @code{typeset}, @code{export}, @code{readonly},
@@ -1863,7 +1862,7 @@ builtin command, or those set by the shell itself
@item $
@vindex $$
($$) Expands to the process @sc{id} of the shell. In a @code{()} subshell, it
($$) Expands to the process @sc{id} of the shell. In a subshell, it
expands to the process @sc{id} of the invoking shell, not the subshell.
@item !
@@ -2844,6 +2843,8 @@ descriptor to close.
If @{@var{varname}@} is supplied, the redirection persists beyond
the scope of the command, allowing the shell programmer to manage
the file descriptor's lifetime manually.
The @code{varredir_close} shell option manages this behavior
(@pxref{The Shopt Builtin}).
In the following descriptions, if the file descriptor number is
omitted, and the first character of the redirection operator is
@@ -3306,6 +3307,8 @@ shell's parent, and traps ignored by the shell are ignored
A command invoked in this separate environment cannot affect the
shell's execution environment.
A @dfn{subshell} is a copy of the shell process.
Command substitution, commands grouped with parentheses,
and asynchronous commands are invoked in a
subshell environment that is a duplicate of the shell environment,
@@ -3471,7 +3474,7 @@ are unset.
A shell script may be made executable by using the @code{chmod} command
to turn on the execute bit. When Bash finds such a file while
searching the @env{$PATH} for a command, it spawns a subshell to
searching the @env{$PATH} for a command, it creates a subshell to
execute it. In other words, executing
@example
filename @var{arguments}
@@ -5674,6 +5677,11 @@ If set, the @code{.} (@code{source}) builtin uses the value of @env{PATH}
to find the directory containing the file supplied as an argument.
This option is enabled by default.
@item varredir_close
If set, the shell automatically closes file descriptors assigned using the
@code{@{varname@}} redirection syntax (@pxref{Redirections}) instead of
leaving them open when the command completes.
@item xpg_echo
If set, the @code{echo} builtin expands backslash-escape sequences
by default.
+13 -5
View File
@@ -2900,6 +2900,9 @@ yylex ()
return (current_token);
}
if (current_token < 0)
current_token = YYerror;
return (current_token);
}
@@ -4085,10 +4088,11 @@ itrace("parse_comsub: need_here_doc = %d after yyparse()?", need_here_doc);
}
if (current_token != shell_eof_token)
{
{
itrace("current_token (%d) != shell_eof_token (%c)", current_token, shell_eof_token);
token_to_read = current_token;
}
token_to_read = current_token;
return (&matched_pair_error);
}
restore_parser_state (&ps);
@@ -4161,6 +4165,8 @@ xparse_dolparen (base, string, indp, flags)
/*(*/
parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
shell_eof_token = ')';
if (flags & SX_COMPLETE)
parser_state |= PST_NOERROR;
token_to_read = DOLPAREN; /* let's trick the parser */
@@ -4219,7 +4225,8 @@ xparse_dolparen (base, string, indp, flags)
if (base[*indp] != ')' && (flags & SX_NOLONGJMP) == 0)
{
/*(*/
parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), ')');
if ((flags & SX_NOERROR) == 0)
parser_error (start_lineno, _("unexpected EOF while looking for matching `%c'"), ')');
jump_to_top_level (DISCARD);
}
@@ -5878,7 +5885,8 @@ int
yyerror (msg)
const char *msg;
{
report_syntax_error ((char *)NULL);
if ((parser_state & PST_NOERROR) == 0)
report_syntax_error ((char *)NULL);
reset_parser ();
return (0);
}
+1
View File
@@ -49,6 +49,7 @@
#define PST_COMMENT 0x100000 /* parsing a shell comment; used by aliases */
#define PST_ENDALIAS 0x200000 /* just finished expanding and consuming an alias */
#define PST_NOEXPAND 0x400000 /* don't expand anything in read_token_word; for command substitution */
#define PST_NOERROR 0x800000 /* don't print error messages in yyerror */
/* Definition of the delimiter stack. Needed by parse.y and bashhist.c. */
struct dstack {
+1 -1
View File
@@ -25,6 +25,6 @@
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
looks for to find the patch level (for the sccs version string). */
#define PATCHLEVEL 4
#define PATCHLEVEL 8
#endif /* _PATCHLEVEL_H_ */
+24 -11
View File
@@ -1,6 +1,6 @@
/* redir.c -- Functions to perform input and output redirection. */
/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -88,6 +88,7 @@ extern int errno;
#define SHELL_FD_BASE 10
int expanding_redir;
int varassign_redir_autoclose = 0;
extern REDIRECT *redirection_undo_list;
extern REDIRECT *exec_redirection_undo_list;
@@ -949,10 +950,15 @@ do_redirection_internal (redirect, flags, fnp)
REDIRECTION_ERROR (redirector, r, fd);
}
if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
if ((flags & RX_UNDOABLE) && ((redirect->rflags & REDIR_VARASSIGN) == 0 || varassign_redir_autoclose))
{
/* Only setup to undo it if the thing to undo is active. */
if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
/* Only setup to undo it if the thing to undo is active. We want
to autoclose if we are doing a varassign redirection and the
varredir_close shell option is set, and we can't test
redirector in this case since we just assigned it above. */
if (fd != redirector && (redirect->rflags & REDIR_VARASSIGN) && varassign_redir_autoclose)
r = add_undo_close_redirect (redirector);
else if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
r = add_undo_redirect (redirector, ri, -1);
else
r = add_undo_close_redirect (redirector);
@@ -1066,10 +1072,14 @@ do_redirection_internal (redirect, flags, fnp)
if (flags & RX_ACTIVE)
{
if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
if ((flags & RX_UNDOABLE) && ((redirect->rflags & REDIR_VARASSIGN) == 0 || varassign_redir_autoclose))
{
/* Only setup to undo it if the thing to undo is active. */
if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
/* Only setup to undo it if the thing to undo is active.
Close if the right option is set and we are doing a
varassign redirection. */
if (fd != redirector && (redirect->rflags & REDIR_VARASSIGN) && varassign_redir_autoclose)
r = add_undo_close_redirect (redirector);
else if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
r = add_undo_redirect (redirector, ri, -1);
else
r = add_undo_close_redirect (redirector);
@@ -1127,10 +1137,14 @@ do_redirection_internal (redirect, flags, fnp)
if ((flags & RX_ACTIVE) && (redir_fd != redirector))
{
if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
if ((flags & RX_UNDOABLE) && ((redirect->rflags & REDIR_VARASSIGN) == 0 || varassign_redir_autoclose))
{
/* Only setup to undo it if the thing to undo is active. */
if (fcntl (redirector, F_GETFD, 0) != -1)
/* Only setup to undo it if the thing to undo is active.
Close if the right option is set and we are doing a
varassign redirection. */
if ((redirect->rflags & REDIR_VARASSIGN) && varassign_redir_autoclose)
r = add_undo_close_redirect (redirector);
else if (fcntl (redirector, F_GETFD, 0) != -1)
r = add_undo_redirect (redirector, ri, redir_fd);
else
r = add_undo_close_redirect (redirector);
@@ -1219,7 +1233,6 @@ do_redirection_internal (redirect, flags, fnp)
}
r = 0;
/* XXX - only if REDIR_VARASSIGN not set? */
if (flags & RX_UNDOABLE)
{
if (fcntl (redirector, F_GETFD, 0) != -1)
+1 -1
View File
@@ -1961,7 +1961,7 @@ skip_to_delim (string, start, delims, flags)
CQ_RETURN(si);
if (string[i+1] == LPAREN)
temp = extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
temp = extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND|completeflag); /* ) */
else
temp = extract_dollar_brace_string (string, &si, 0, SX_NOALLOC);
CHECK_STRING_OVERRUN (i, si, slen, c);
+3 -1
View File
@@ -1,6 +1,6 @@
/* subst.h -- Names of externally visible functions in subst.c. */
/* Copyright (C) 1993-2017 Free Software Foundation, Inc.
/* Copyright (C) 1993-2021 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -71,6 +71,7 @@
#define SX_WORD 0x0200 /* extracting word in ${param op word} */
#define SX_COMPLETE 0x0400 /* extracting word for completion */
#define SX_STRIPDQ 0x0800 /* strip double quotes when extracting double-quoted string */
#define SX_NOERROR 0x1000 /* don't print parser error messages */
/* Remove backslashes which are quoting backquotes from STRING. Modifies
STRING, and returns a pointer to it. */
@@ -314,6 +315,7 @@ extern char *cond_expand_word PARAMS((WORD_DESC *, int));
#define SD_COMPLETE 0x100 /* skip_to_delim during completion */
#define SD_HISTEXP 0x200 /* skip_to_delim during history expansion */
#define SD_ARITHEXP 0x400 /* skip_to_delim during arithmetic expansion */
#define SD_NOERROR 0x800 /* don't print error messages */
extern int skip_to_delim PARAMS((char *, int, char *, int));
-1
View File
@@ -5,7 +5,6 @@ hi
hi
./comsub-eof3.sub: line 4: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
./comsub-eof3.sub: line 5: unexpected EOF while looking for matching `)'
./comsub-eof3.sub: line 5: unexpected EOF while looking for matching `)'
./comsub-eof4.sub: line 3: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
contents
./comsub-eof5.sub: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `)')
-1
View File
@@ -286,4 +286,3 @@ argv[1] = <"A">
argv[1] = <A>
argv[1] = <A>
./posixexp.tests: line 97: unexpected EOF while looking for matching `}'
./posixexp.tests: line 98: syntax error: unexpected end of file
+3
View File
@@ -53,6 +53,7 @@ shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
shopt -u varredir_close
shopt -u xpg_echo
--
shopt -u huponexit
@@ -112,6 +113,7 @@ shopt -u nullglob
shopt -u progcomp_alias
shopt -u restricted_shell
shopt -u shift_verbose
shopt -u varredir_close
shopt -u xpg_echo
--
autocd off
@@ -154,6 +156,7 @@ nullglob off
progcomp_alias off
restricted_shell off
shift_verbose off
varredir_close off
xpg_echo off
--
set +o allexport
+1
View File
@@ -98,3 +98,4 @@ swizzle ()
exec {stdin}<&${fd[0]}-;
exec {stdout}>&${fd[1]}-
}
./vredir8.sub: line 12: $fd: Bad file descriptor
+1
View File
@@ -57,5 +57,6 @@ ${THIS_SH} ./vredir5.sub
${THIS_SH} ./vredir6.sub
${THIS_SH} ./vredir7.sub
${THIS_SH} ./vredir8.sub
exit 0
+13
View File
@@ -0,0 +1,13 @@
# test varredir_close
: {fd}<>/dev/null
echo redir 1 >&$fd
exec {fd}>&-
shopt -s varredir_close
: {fd}<>/dev/tty
echo redir 2 >&$fd
exec {fd}>&-