zsh: is there a problem with always enabling extended glob?
I would assume the potential issue is that ^
is quite a valid character in file names, so the meaning of a pattern containing it changes based on if the option is set or not:
$ touch 'foo' 'bar' '^foo' '^bar'
$ ls ^foo*
^foo
$ setopt extendedglob
$ ls ^foo*
bar ^bar ^foo
A standard shell would take the ^
as an ordinary character, so the feature is probably disabled by default for compatibility.
As long as you remember what options are enabled, i.e. know how the shell interprets the globs, leaving extended_glob
enabled shouldn't be a problem in interactive use.
For scripts that don't expect it but use weird filenames, it would be an issue, but non-interactive shells shouldn't read .zshrc
, so setting it there should be ok. Just don't set it in .zshenv
.
The ksh-style extended globs (@(...|...)
etc., setopt kshglob
) have a similar issue in that they conflict with how zsh handles parenthesis in globs. @(f|b)
means different things depending on if kshglob
is set or not.
Related videos on Youtube
daniel451
Updated on September 18, 2022Comments
-
daniel451 over 1 year
I recetnly came across
setopt extended_glob
...in order to enable extended globbing which allows for a number of cool wildcard additions, like excluding specific patterns, for example:
ls ^foo*
...will use
ls
on every path in your current directory except for patterns that matchfoo*
.I found one tutorial suggesting to put
setopt extended_glob
inside your.zshrc
, but I guess since many zsh config templates miss that option and the option being disabled by default it has some downsides or even side-effects?Or is it absolutely harmless always enabling
extended_glob
via putting it inside one's.zshrc
? -
Stéphane Chazelas about 6 yearsNote that
^
is special in several other shells (Bourne, rc, akanga, es, fish). Also in csh, tcsh, bash when the first character of a command line.a~b
(also special with extendedglob) is not special in any though. -
Stéphane Chazelas about 6 yearsksh globs also conflict with Bourne/POSIX when used in expansions. For instance
a='@(*)'; echo $a
is meant to output the file names that start with@(
and end with)
but outputs all non-hidden files insteadbash -O extglob
orzsh -o kshglob -o globsubst -o nobareglobquals
. ksh does not recognise them when used in the result of expansions. -
Zaroth almost 5 years
^
is also often used in git commands, such asgit diff HEAD^
which makes the use of it in zsh quite problematic if you use git often.