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: Mon, 7 Jun 2021 01:35:21 +0200

Hello,

> Personally, I'd just want an option to always make . and .. hidden from
> globs. [...]

If such option existed, I would certainly use it.
As I already said, I can't imagine why anyone would ever want a pattern to 
match `.' or `..' (unless the entire path component is literal).
But even if I had such option, I would still want the default behavior to be 
easy to understand and fully documented, therefore I maintain my proposed 
changes.
__

About dotglob, this is subjective but personally I would never prefer to have 
it unset.
It happened to me quite a few times that I forgot to include dot files by 
accident, but never the other way around (even after ten years of dotglob set).
When it is not a very conscious choice and I just think "I want all files", 
usually all means all.
When I don't want dot files (rarely), I'm usually very aware of it and I just 
use `[^.]*'.

And even more importantly, dotglob allows me to exclude `.' and `..' by 
protecting the leading dot with brackets. From your example:

$ touch .dot normal
$ echo [.]*
.dot
$ echo ./[.]*
./.dot

> For what it's worth, Zsh, mksh and fish seem to always hide . and ..

Just for curiosity, is that still standard compliant? (I'm talking about 
non-extended patterns, like `.*')

> I tried to achieve that via GLOBIGNORE=.:.. , but that has the problem that
> it forces dotglob on, and looks at the whole resulting path, so ./.* still
> gives ./. and ./.. . Unless you use GLOBIGNORE=.:..:*/.:*/.. etc., but
> repeating the same for all different path lengths gets a bit awkward.

Yes, I also tried GLOBIGNORE a long time ago, and it won't cut the salami.
I think GLOBIGNORE=.:.. is error prone because you get used to it and then you 
get bitten when there is more than one path component.
If you want to cover all cases, there's no need to take into account all 
different path lengths because `/' is not special. You just have to cover 4 
cases (alone, at start, in the middle, at end):
GLOBIGNORE=.:..:./*:../*:*/./*:*/../*:*/.:*/..
But the effect is still not useful (e.g. `./*.txt' will fail to match 
`./foo.txt').

While I'm at it, I will also point out that the docs suggest adding `.*' to 
GLOBIGNORE if the automatic activation of dotglob is undesirable.
I think such suggestion is misleading because the effect is very different 
(e.g. with dotglob unset `.bash*' still matches `.bashrc' etc. but with 
GLOBIGNORE=.* it won't).

Regards,
NP



reply via email to

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