Alexandre Ferrieux <
alexandre...@gmail.com> wrote:
>> FWIW, in unix-shell (bash - probably others, too):
>> $ touch 'abc[def]ghi'
>> $ echo *[]]*
>> abc[def]ghi
>> Was it an oversight in the specification of Tcl's glob, or was it
>> deliberately left out?
> From a 'fossil annotate' on tclUtil.c, function Tcl_StringCaseMatch:
> 16f0a0d493 1999-12-04 hobbs: while (1) {
> 16f0a0d493 1999-12-04 hobbs: if ((*pattern == ']') || (*pattern
>== '\0')) {
> 16f0a0d493 1999-12-04 hobbs: return 0;
> 16f0a0d493 1999-12-04 hobbs: }
> (and the lack of special casing nor comments to that regard)
> ... it seems that this Day One limitation comes from the fact that
> nobody cared (nor cares, to be frank) about strict compatibility with
> shell globbing.
I wouldn't care about []], if at least there was [\]] in glob patterns.
"Strict compatibility with shell-globbing" surely isn't all that important,
but being able to include close-brackets in character sets would be really
neat, and the implementation would be quite trivial:
change (in the quoted fossil snippet)
if ((*pattern == ']') || (*pattern == '\0')) {
to
if ( (*pattern == '\0') ||
( (*pattern == ']') && pattern > firstsetcharpos ) ) {
and set firstsetcharpos to pattern+1 where the open '[' is hit.
Actually, there is another dirty hack for the OP:
glob {*{[[{}()],]}*}
but that finds a file with both [ and ] in its name twice. ;-)
> In hindsight, 99% compat is okay if the 1% has a
> noticeable complexity cost.
Agree, but does it?
I figure you'll point out documentation now:
"A ] may be matched by including it as the first character in the set."
That's how bash describes it.