Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug in extended pattern matching *!()

13 views
Skip to first unread message

hans1...@gmail.com

unread,
Sep 26, 2012, 10:07:23 PM9/26/12
to
See also this thread: http://stackoverflow.com/questions/12596468/

It looks like there is some bug in the pattern matcher

$ shopt -s extglob
$ touch a ab ba
$ echo a*!(x)

Expected result:
a ab
Experienced result:
ab

This is particularly weird since other combinations work fine:
$ echo *!(x)a
a ba
$ echo !(x)*a
a ba
$ echo a!(x)*
a ab

I assume it has something to do with the EXTMATCH implementation in lib/glob/sm_loop.c, but I haven't been able to figure out what exactly the problem is. Not sure if I fully understand the idea behind the for-loops there.

Chet Ramey

unread,
Sep 27, 2012, 8:58:37 PM9/27/12
to hans1...@gmail.com, bug-...@gnu.org, chet....@case.edu
On 9/26/12 10:07 PM, hans1...@gmail.com wrote:
> See also this thread: http://stackoverflow.com/questions/12596468/
>
> It looks like there is some bug in the pattern matcher
>
> $ shopt -s extglob
> $ touch a ab ba
> $ echo a*!(x)
>
> Expected result:
> a ab
> Experienced result:
> ab

The question is whether or not !(x) should match the empty string. The
bash matcher treats it similarly to [!x], which does not.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/

hans1...@gmail.com

unread,
Sep 28, 2012, 12:52:56 AM9/28/12
to hans1...@gmail.com, bug-...@gnu.org, chet....@case.edu
> The question is whether or not !(x) should match the empty string. The
> bash matcher treats it similarly to [!x], which does not.

It does however match the empty string at most times. So I guess that's the real bug. Again, there is some inconsistency in

$ echo *!(x)a # does match empty string
a ba
$ echo a*!(x) # does not
ba



[OT] Thanks for your work for the Bash project. I've just learned that you've been the main maintainer for a long time, so keep it up! :)

hans1...@gmail.com

unread,
Sep 28, 2012, 12:55:22 AM9/28/12
to hans1...@gmail.com, bug-...@gnu.org, chet....@case.edu
> $ echo a*!(x) # does not
> ba

Sorry, that should of course be

$ echo a*!(x) # does not
ab

hans1...@gmail.com

unread,
Sep 28, 2012, 12:52:56 AM9/28/12
to gnu.ba...@googlegroups.com, hans1...@gmail.com, bug-...@gnu.org, chet....@case.edu
> The question is whether or not !(x) should match the empty string. The
> bash matcher treats it similarly to [!x], which does not.

It does however match the empty string at most times. So I guess that's the real bug. Again, there is some inconsistency in

$ echo *!(x)a # does match empty string
a ba
$ echo a*!(x) # does not
ba



hans1...@gmail.com

unread,
Sep 28, 2012, 12:55:22 AM9/28/12
to gnu.ba...@googlegroups.com, hans1...@gmail.com, bug-...@gnu.org, chet....@case.edu
> $ echo a*!(x) # does not
> ba

Sorry, that should of course be

$ echo a*!(x) # does not
ab

Chet Ramey

unread,
Sep 28, 2012, 9:11:35 AM9/28/12
to hans1...@gmail.com, gnu.ba...@googlegroups.com, bug-...@gnu.org, chet....@case.edu
On 9/28/12 12:52 AM, hans1...@gmail.com wrote:
>> The question is whether or not !(x) should match the empty string. The
>> bash matcher treats it similarly to [!x], which does not.
>
> It does however match the empty string at most times. So I guess that's the real bug. Again, there is some inconsistency in

It's whether or not it matches the NUL at the end of the search string. I
agree that it should, or at least that (x) should not match, so !(x)
should, and that will be fixed for the next version.

> [OT] Thanks for your work for the Bash project. I've just learned that you've been the main maintainer for a long time, so keep it up! :)

:-)

DJ Mills

unread,
Sep 28, 2012, 11:21:25 AM9/28/12
to Chester Ramey, bug-...@gnu.org
On Fri, Sep 28, 2012 at 12:52 AM, <hans1...@gmail.com> wrote:
> [OT] Thanks for your work for the Bash project. I've just learned that you've been the main maintainer for a long time, so keep it up! :)

+1000 to that, bash makes my life so much easier and I doubt you get
enough thanks

0 new messages