From: "Andreas Kusalananda Kähäri" <andreas.kahari@abc.se>
To: Oğuz <oguzismailuysal@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: variable expanding to `*` matches a literal `*` in case cond. construct
Date: Sun, 15 Dec 2019 11:05:07 +0100 [thread overview]
Message-ID: <20191215100507.GA23773@pooh.my.domain> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2019-12-15 10:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-15 8:41 Oğuz
2019-12-15 10:05 ` Andreas Kusalananda Kähäri [this message]
2019-12-15 11:04 ` Oğuz
2019-12-15 12:02 ` Andreas Kusalananda Kähäri
2019-12-15 12:50 ` Oğuz
2019-12-15 22:49 ` Eric Cook
2019-12-15 23:27 ` Dominik Vogt
2019-12-16 0:02 ` Perry Smith
2019-12-16 0:03 ` dana
2019-12-16 0:23 ` Oğuz
2019-12-16 0:28 ` Mikael Magnusson
2019-12-16 5:25 ` Lewis Butler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191215100507.GA23773@pooh.my.domain \
--to=andreas.kahari@abc.se \
--cc=oguzismailuysal@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).