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: Nora Platiel
Subject: Re: !(.pattern) can match . and .. if dotglob is enabled
Date: Thu, 27 May 2021 01:36:36 +0200

Hello,

> This is behavior that changed more than ten years ago.

I thought it changed in this commit:
https://git.savannah.gnu.org/cgit/bash.git/commit/?id=ac50fbac377e32b98d2de396f016ea81e8ee9961
2014-02-26 -> 7.2 years ago
But yes, I know it's old stuff and I was not implying a regression, just 
mentioning it FYI.

> There was a relevant discussion back in January:
> https://lists.gnu.org/archive/html/bug-bash/2021-01/msg00240.html

Thanks, I did a search but I missed it.
It *is* relevant, because I think that @(?|.?) matching '.' is consistent with 
!(.foo) matching '.' and '..'

If you maintain that such behavior is correct, I have no problem with it.
I will just use [.]pattern even inside !(...) to get rid of '.' and '..'

The problem is, there is nothing in the docs that hints at such behavior.
I.e. that the pattern beginning with a literal dot may not match at all, but it 
still signal that '.' and '..' should be accepted in the final match.
The docs only talk about the requirement of '.' and  '..' to "be matched 
explicitly", which is vague and subject to interpretation, especially in the 
context of extended patterns.
I'm not the first person to complain about such wording.

> When dotglob is enabled, the shell's pattern matcher interprets an extglob
> pattern beginning with a literal `.' as specifying that files beginning
> with a `.' should match, so the negated pattern matches `.' and `..'.

Shouldn't this be the case with dotglob disabled?
And with dotglob enabled, the exclusion applies only to '.' and '..', instead 
of all dot-files.
If not, again the docs is wrong or incomplete.

dotglob enabled  -> '.' and  '..' require pattern beginning with literal dot
dotglob disabled -> all dot-files require pattern beginning with literal dot

I.e. my understanding is that every pattern starting with a literal dot should 
*not* be influenced by dotglob, because the literal dot calls off every 
exclusion.

Of course dotglob makes no difference here:
$ shopt -s dotglob; echo @(.*)
. .. .a
$ shopt -u dotglob; echo @(.*)
. .. .a

$ shopt -s dotglob; echo @(.?)
.. .a
$ shopt -u dotglob; echo @(.?)
.. .a

So why it does here?
$ shopt -s dotglob; echo @(.foo|*)
. .. .a b
$ shopt -u dotglob; echo @(.foo|*)
b

$ shopt -s dotglob; echo !(.foo)
. .. .a b
$ shopt -u dotglob; echo !(.foo)
b

Regards,
NP



reply via email to

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