I have setopt extended_glob
, I want to exclude all files under ~/.config/zsh
that either start with _
or filename is completion.zsh
or options.zsh
I have this command:
for f (${${(%):-%x}:P:h:h}/**/([^_|^completion|^options])*.zsh) print $f
It does the job but above command also exclude lazyload.zsh
, why above command exclude this pattern? I expected it will print out lazyload.zsh
.
Best Answer
Just:
^
is theextendedglob
negation operator.Remember
[anything]
only ever matches one character¹.[a|b]
matchesa
,|
orb
,[^a|b]
matches any character buta
,|
orb
.So your pattern excludes
lazyload.zsh
becausel
is in the list of character excluded by your[^...]
single-character-matching operator.¹ (in
zsh
; in some other shells, it may also match multi-character collating elements in some locales; zsh's[...]
can also match bytes not forming parts of valid characters, YMMV with other shells)