Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

$~var and backslash

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

and the discussion that follows at
(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

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


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


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.


Messages sorted by: Reverse Date, Date, Thread, Author