Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
pattern matching, when the pattern is a parameter expansion
- X-seq: zsh-workers 47906
- From: Greg Klanderman <gak@xxxxxxxxxxxxxx>
- To: Zsh list <zsh-workers@xxxxxxx>
- Subject: pattern matching, when the pattern is a parameter expansion
- Date: Wed, 3 Feb 2021 10:51:37 -0500
- Archived-at: <https://zsh.org/workers/47906>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-02/24602.50825.244206.559048%40lwm.klanderman.net>
- List-id: <zsh-workers.zsh.org>
- Reply-to: Greg Klanderman <gak@xxxxxxxxxxxxxx>
Hi,
I seem to have found an inconsistency with pattern matching,
when the pattern is a parameter expansion:
% z=(one two three)
in three syntactic forms that accept a pattern, the pattern can be the
result of a parameter expansion:
% x=two
% [[ two == $x ]] && echo yes || echo no
yes
% echo "${(@)z:#$x}"
one three
% echo "${z[(i)$x]}"
2
now, when x contains an actual pattern rather than a simple string, it
is not matched in the first two cases, but is in the final case:
% x='t*'
% [[ two == $x ]] && echo yes || echo no
no
% echo "${(@)z:#$x}"
one two three
% echo "${z[(i)$x]}"
2
I would have actually expected to match in the first two cases as
well; is this behavior of using plain string matching when the pattern
is a parameter expected documented?
(I know I can get that behavior with the 'e' subscript flag in the
final case)
There is some explanation of pattern matching in Chapter 12
(Conditional Expressions) which seems relevant but not clear on these
cases:
| Normal shell expansion is performed on the file, string and pattern
| arguments, but the result of each expansion is constrained to be a
| single word, similar to the effect of double quotes.
..
| Pattern metacharacters are active for the pattern arguments; the
| patterns are the same as those used for filename generation, see
| Section 14.8 [Filename Generation], page 73, but there is no special
| behaviour of ?/? nor initial dots, and no glob qualifiers are allowed.
thank you,
Greg
Messages sorted by:
Reverse Date,
Date,
Thread,
Author