zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: $~var and backslash
Date: Tue, 18 Jun 2019 21:34:14 +0100	[thread overview]
Message-ID: <20190618203414.ug45yfb3a3ncbg4k@chaz.gmail.com> (raw)

There's currently a discussion on the POSIX mailing list around
the meaning of \ in shell wildcard patterns (beside its meaning
as a quoting operator).

See
http://austingroupbugs.net/view.php?id=1234
and the discussion that follows at
https://www.mail-archive.com/austin-group-l@opengroup.org/msg03630.html
(beware it's long and still ongoing).

That's just for context, no need to read the whole discussion
to understand what I'm saying below.

zsh does seem to be doing some level of processing of backslash
when it comes to \ and pattern matching and globbing, it's not
much worse than several other shells, but I have noted a few
problems.

1. (and the main one) it's completely undocumented (and it's the
same in all the other shells that somehow treat \ as a wildcard
quoting operator).

That:

pattern='\*' string='*' zsh -c '[[ $string = $~pattern ]] && echo yes'

should output "yes" and not

pattern='\*' zsh -c '[[ $pattern = $~pattern ]] && echo yes'

is AFAICT not documented at all.

2. I'm not sure I can find a logic behind when \ is understood
as a quoting operator:

string='\x' pattern='\x' matches
string='\+' pattern='\+' matches

But:

string='?' pattern='\?' matches
string='*' pattern='\*' matches
string='\' pattern='\\' matches

ok, those are wildcard operators, but:

string='\-' pattern='\-' doesn't match (but matches on string='-')
is it because - is special in <1-3> or in [a-b], but then:
string='\' pattern='[a\-a]' matches and also on
string='-' pattern='[a\-a]'
(so \ has escaped - but has not been removed?)

Same for ^ and !.

string='|' pattern='\|' matches but not with shglob. Yet
string='~' pattern='\~' matches both with and without shglob.

It doesn't make much sense to me.

One can always use [|] pr [~] instead of \ (which is also the
most portable in other shells), so it's not very critical.

-- 
Stephane

                 reply	other threads:[~2019-06-19  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190618203414.ug45yfb3a3ncbg4k@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=zsh-workers@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).