Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: variable expanding to `*` matches a literal `*` in case cond. construct
- X-seq: zsh-users 24538
- From: Andreas Kusalananda Kähäri <andreas.kahari@xxxxxx>
- To: Oğuz <oguzismailuysal@xxxxxxxxx>
- Subject: Re: variable expanding to `*` matches a literal `*` in case cond. construct
- Date: Sun, 15 Dec 2019 11:05:07 +0100
- Cc: zsh-users@xxxxxxx
- In-reply-to: <CAH7i3Loe=j+cQXOCMKyy0=efmRxkzaONqaiCYpn9oA--_cYg3Q@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: Oğuz <oguzismailuysal@xxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAH7i3Loe=j+cQXOCMKyy0=efmRxkzaONqaiCYpn9oA--_cYg3Q@mail.gmail.com>
On Sun, Dec 15, 2019 at 11:41:38AM +0300, Oğuz wrote:
> Although one would expect it to print "match"
>
> zsh -c 'case foo in $1) echo match; esac' sh '*'
>
> above command doesn't print anything; if `*` is a result of a variable
> expansion,
> it matches only a literal asterisk. All the other shells I could find
> (including ksh
> from 2010) does print "match". I know this is a compliancy issue and zsh
> doesn't
> claim to be compatible with any other shell, I really wonder; was this
> intended?
> If yes, what was the incentive for that, what's it good for?
>
> --
> Oğuz
In zsh, I suppose you would use ${~1}
$ zsh -c 'case foo in ${~1}) echo match; esac' sh '*'
match
$ zsh -c 'case foo in ${~1}) echo match; esac' sh '??'
$ zsh -c 'case foo in ${~1}) echo match; esac' sh '???'
match
From the manual:
${~spec}
Turn on the GLOB_SUBST option for the evaluation of spec; if the
`~' is doubled, turn it off. When this option is set, the
string resulting from the expansion will be interpreted as a
pattern anywhere that is possible, such as in filename expansion
and filename generation and pattern-matching contexts like the
right hand side of the `=' and `!=' operators in conditions.
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
Messages sorted by:
Reverse Date,
Date,
Thread,
Author