[Top][All Lists]

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

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

From: Nora Platiel
Subject: !(.pattern) can match . and .. if dotglob is enabled
Date: Wed, 26 May 2021 02:58:52 +0200

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux columbus 4.4.246-gentoo #2 SMP Thu Dec 31 17:31:16 -00 2020 
i686 AMD Athlon(tm) XP 2800+ AuthenticAMD GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 5.1
Patch Level: 8
Release Status: release


$ shopt -s dotglob extglob
$ echo !(.foo)
. .. .other files

The doc says: "The filenames '.' and '..' must always be matched explicitly, 
even if dotglob is set."
I would infer that a !(...) should never match '.' and '..', because you cannot 
match something literally using an operator that means "anything except".

The patterns .foo and [.]foo are equivalent under dotglob, therefore I would 
expect !(.foo) and !([.]foo) to be also equivalent. But . and .. are excluded 
here already:
$ shopt -s dotglob extglob
$ echo !([.]foo)
.other files
$ echo !(foo)
.other files

Personally I can't imagine how it can be ever useful for a pattern to match . 
or .. (unless the path component is literally . or ..).
Therefore I always work with dotglob enabled and use [.]pattern instead of 
.pattern to get rid of . and ..
But I don't think it makes much sense with the !(...) operator.
Also the pattern !(.foo) didn't match . and .. before version 4.3.0.


reply via email to

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