summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y34
1 files changed, 24 insertions, 10 deletions
diff --git a/parse.y b/parse.y
index 7e82d3de..d887eecb 100644
--- a/parse.y
+++ b/parse.y
@@ -4063,10 +4063,11 @@ parse_comsub (qc, open, close, lenp, flags)
int *lenp, flags;
{
int peekc, r;
- int start_lineno;
+ int start_lineno, local_extglob, was_extpat;
char *ret, *tcmd;
int retlen;
sh_parser_state_t ps;
+ STRING_SAVER *saved_strings;
COMMAND *saved_global, *parsed_command;
/* Posix interp 217 says arithmetic expressions have precedence, so
@@ -4086,7 +4087,7 @@ parse_comsub (qc, open, close, lenp, flags)
save_parser_state (&ps);
- pushed_string_list = (STRING_SAVER *)NULL;
+ was_extpat = (parser_state & PST_EXTPAT);
/* State flags we don't want to persist into command substitutions. */
parser_state &= ~(PST_REGEXP|PST_EXTPAT|PST_CONDCMD|PST_CONDEXPR|PST_COMPASSIGN);
@@ -4098,6 +4099,8 @@ parse_comsub (qc, open, close, lenp, flags)
/* State flags we want to set for this run through the parser. */
parser_state |= PST_CMDSUBST|PST_EOFTOKEN|PST_NOEXPAND;
+ /* leave pushed_string_list alone, since we might need to consume characters
+ from it to satisfy this command substitution (in some perverse case). */
shell_eof_token = close;
saved_global = global_command; /* might not be necessary */
@@ -4114,9 +4117,13 @@ parse_comsub (qc, open, close, lenp, flags)
if (expand_aliases)
expand_aliases = posixly_correct != 0;
#if defined (EXTENDED_GLOB)
- global_extglob = extended_glob;
- if (shell_compatibility_level <= 51)
- extended_glob = 1;
+ /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a
+ conditional command and have already set global_extglob appropriately. */
+ if (shell_compatibility_level <= 51 && was_extpat == 0)
+ {
+ local_extglob = global_extglob = extended_glob;
+ extended_glob = 1;
+ }
#endif
current_token = '\n'; /* XXX */
@@ -4131,7 +4138,8 @@ parse_comsub (qc, open, close, lenp, flags)
}
#if defined (EXTENDED_GLOB)
- extended_glob = global_extglob;
+ if (shell_compatibility_level <= 51 && was_extpat == 0)
+ extended_glob = local_extglob;
#endif
parsed_command = global_command;
@@ -4158,7 +4166,7 @@ parse_comsub (qc, open, close, lenp, flags)
shell_eof_token = ps.eof_token;
expand_aliases = ps.expand_aliases;
- jump_to_top_level (DISCARD);
+ jump_to_top_level (DISCARD); /* XXX - return (&matched_pair_error)? */
}
}
@@ -4177,7 +4185,12 @@ INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token, she
return (&matched_pair_error);
}
+ /* We don't want to restore the old pushed string list, since we might have
+ used it to consume additional input from an alias while parsing this
+ command substitution. */
+ saved_strings = pushed_string_list;
restore_parser_state (&ps);
+ pushed_string_list = saved_strings;
tcmd = print_comsub (parsed_command); /* returns static memory */
retlen = strlen (tcmd);
@@ -4259,7 +4272,7 @@ xparse_dolparen (base, string, indp, flags)
old value will be restored by restore_parser_state(). */
expand_aliases = 0;
#if defined (EXTENDED_GLOB)
- global_extglob = extended_glob;
+ global_extglob = extended_glob; /* for reset_parser() */
#endif
token_to_read = DOLPAREN; /* let's trick the parser */
@@ -4597,7 +4610,7 @@ cond_term ()
{
WORD_DESC *op;
COND_COM *term, *tleft, *tright;
- int tok, lineno;
+ int tok, lineno, local_extglob;
char *etext;
/* Read a token. It can be a left paren, a `!', a unary operator, or a
@@ -4711,11 +4724,12 @@ cond_term ()
}
/* rhs */
+ local_extglob = extended_glob;
if (parser_state & PST_EXTPAT)
extended_glob = 1;
tok = read_token (READ);
if (parser_state & PST_EXTPAT)
- extended_glob = global_extglob;
+ extended_glob = local_extglob;
parser_state &= ~(PST_REGEXP|PST_EXTPAT);
if (tok == WORD)