bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: !(.pattern) can match . and .. if dotglob is enabled


From: Ilkka Virta
Subject: Re: !(.pattern) can match . and .. if dotglob is enabled
Date: Sun, 6 Jun 2021 14:39:19 +0300

On Sun, Jun 6, 2021 at 1:31 PM Ilkka Virta <itvirta@gmail.com> wrote:

> Personally, I'd just want an option to always make . and .. hidden from
> globs. Or rather,
> to never generate . or .. as a pathname component via globbing. But
> without affecting
> other behaviour, like dotglob, and without precluding the use of . or ..
> as static parts of the
> path.
>

Hmm, looking at the code, this already seems to exist, in lib/glob/glob.c:

   /* Global variable controlling whether globbing ever returns . or ..
     regardless of the pattern. If set to 1, no glob pattern will ever
     match `.' or `..'. Disabled by default. */
  int glob_always_skip_dot_and_dotdot = 1;

I didn't read all the code, but as far as I tested from the git version,
that seems to do what I just
wanted and seems sensible to me with Nora's examples too. (I changed the
filenames from the
previous since I started copying their tests now.)

$ touch .foo .doo bar quux

With dotglob (the first is the same as just *):

$ shopt -s dotglob
$ echo @(.foo|*)
bar .doo .foo quux
$ echo !(.foo)
bar .doo quux
$ echo @(bar|.*)
bar .doo .foo

Without it:

$ shopt -u dotglob
$ echo @(.foo|*)
bar .foo quux
$ echo @(bar|.*)
bar .doo .foo

No match for . and .. even explicitly (with failglob here):

$ echo @(.|..)
bash: no match: @(.|..)

All files with dotglob unset:

$ echo @(.|)*
bar .doo .foo quux

Maybe I missed some more obscure case, though.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]