extglob patterns and dotfiles

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

extglob patterns and dotfiles

Eric Cook
When using an pattern that begin with an period in pattern-list, bash will include dotfiles in the results.
This doesn't seem to be the case with the various korn shells that i have seen. Since extglob is based on
ksh's extension to globbing, this appears to be an bug.


$ shopt -s extglob; touch .c
$ echo !(.a|.b)
. .. .c
$ ksh
$ echo !(.a|.b)
!(.a|.b)
$ mksh
$ echo !(.a|.b)
!(.a|.b)

When !(...) is prefixed with an period, ksh93 will match ., .. and .c while mksh matches .c
i would expect bash to match ., .. and .c to be consistent with how .* behaves currently in bash.

Reply | Threaded
Open this post in threaded view
|

Re: extglob patterns and dotfiles

Chet Ramey
On 12/29/17 6:55 PM, Eric Cook wrote:
> When using an pattern that begin with an period in pattern-list, bash will include dotfiles in the results.
> This doesn't seem to be the case with the various korn shells that i have seen. Since extglob is based on
> ksh's extension to globbing, this appears to be an bug.

It's an interesting question. .c certainly doesn't match any of the
subpatterns. I guess including a `.' as the leading character in the
subpatterns shouldn't allow filenames beginning with `.' to be returned
as not matching. I'll take a look.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/

Reply | Threaded
Open this post in threaded view
|

Re: extglob patterns and dotfiles

Eric Cook
On 12/31/2017 01:47 PM, Chet Ramey wrote:

> On 12/29/17 6:55 PM, Eric Cook wrote:
>> When using an pattern that begin with an period in pattern-list, bash will include dotfiles in the results.
>> This doesn't seem to be the case with the various korn shells that i have seen. Since extglob is based on
>> ksh's extension to globbing, this appears to be an bug.
>
> It's an interesting question. .c certainly doesn't match any of the
> subpatterns. I guess including a `.' as the leading character in the
> subpatterns shouldn't allow filenames beginning with `.' to be returned
> as not matching. I'll take a look.
>
> Chet
>

I guess the behavior is a little more subtle than that, with ksh93.

ksh93 $ touch a .c
ksh93 $ echo @(|.)!(b|c)
. .. a

I personally would expect .c being omitted since @(.|) is an logical or
of . and empty string. but at the moment with bash .c is still matched.

mksh, openbsd ksh and pdksh avoid the ambiguity(?) by not allowing dotfiles
to be matched at all with [@*?+!]() which i think bash probably
should not follow, since it historically does match dotfiles.

So to make my request more specific, i don't think the extglob !() should
match dotfiles when one of the patterns in the list is preceded with an period.
to be more ksh93-like.


Reply | Threaded
Open this post in threaded view
|

Re: extglob patterns and dotfiles

Chet Ramey
On 12/31/17 10:36 PM, Eric Cook wrote:

> So to make my request more specific, i don't think the extglob !() should
> match dotfiles when one of the patterns in the list is preceded with an period.
> to be more ksh93-like.

Let's see if we can be more precise: if a filename beginning with a `.'
does not match any of the patterns in a !(...) list, don't return it as
a match if the leading dot has to be explicitly matched.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/

Reply | Threaded
Open this post in threaded view
|

Re: extglob patterns and dotfiles

Eric Cook
On 01/02/2018 10:30 AM, Chet Ramey wrote:

> On 12/31/17 10:36 PM, Eric Cook wrote:
>
>> So to make my request more specific, i don't think the extglob !() should
>> match dotfiles when one of the patterns in the list is preceded with an period.
>> to be more ksh93-like.
>
> Let's see if we can be more precise: if a filename beginning with a `.'
> does not match any of the patterns in a !(...) list, don't return it as
> a match if the leading dot has to be explicitly matched.
>
> Chet
>

That sounds right, i personally thought (and i could be wrong) of !()
like `*', but excluding anything matching the patterns inside.
so without dotglob enabled or being prefixed with ., !() would
not match dotfiles.