zsh-workers
 help / color / mirror / code / Atom feed
* $~var and backslash
@ 2019-06-18 20:34 Stephane Chazelas
  0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2019-06-18 20:34 UTC (permalink / raw)
  To: Zsh hackers list

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-19  8:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 20:34 $~var and backslash Stephane Chazelas

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).