GNU bug report logs - #54043
Simple regexp bug [contains spoiler for today's wordle]

Previous Next

Package: grep;

Reported by: Matthew Wilcox <willy <at> infradead.org>

Date: Thu, 17 Feb 2022 14:51:02 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 54043-done <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Matthew Wilcox <willy <at> infradead.org>
Cc: 54043-done <at> debbugs.gnu.org
Subject: Re: bug#54043: Simple regexp bug [contains spoiler for today's wordle]
Date: Thu, 17 Feb 2022 08:13:54 -0800
On Thu, Feb 17, 2022 at 7:46 AM Matthew Wilcox <willy <at> infradead.org> wrote:
> I noticed this one while doing:
>
> $ grep sha[^s]e five-letter-words
> share
>
> which doesn't fit with:
>
> $ grep sha.e five-letter-words
> shade
> shake
> shale
> shame
> shape
> share
> shave
>
> A reproducer is easy:
>
> $ echo shame |grep sha[^s]e
> (no output)

This is not a bug in grep. Your failure to quote the regular expression
means that the argument is first interpreted by the shell.
To demonstrate the argument that "grep" ends up using,
run this from that same directory:

  echo sha[^s]e

If I have something named e.g., "shape" in the current directory, that
would print "shape". If I have two matching names, e.g., shave and shale,
it will print both names.

IMHO, it is almost always best to single-quote regular expressions like that.
Quoting your reproducer, you see it works as desired:

  $ echo shame |grep 'sha[^s]e'
  shame




This bug report was last modified 3 years and 95 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.