GNU bug report logs - #71252
why does grep match literal newlines when there are none, even with -z?

Previous Next

Package: grep;

Reported by: Philippe Cerfon <philcerf <at> gmail.com>

Date: Wed, 29 May 2024 01:04:02 UTC

Severity: normal

Tags: notabug

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philippe Cerfon <philcerf <at> gmail.com>
To: gnu <at> schrader-schulte.de
Cc: 71252 <at> debbugs.gnu.org
Subject: bug#71252: why does grep match literal newlines when there are none, even with -z?
Date: Thu, 30 May 2024 06:14:09 +0200
On Wed, May 29, 2024 at 8:09 AM Martin Schulte <gnu <at> schrader-schulte.de> wrote:

> PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern.

Dammit, it's so obvious. Sorry for the noise.

Well actually, there is still one curious point left:
If these are now two patterns, than it's two times the empty pattern, right?

I recently stumbled over this in another area, and as far as I
understand POSIX does not define what should happen with BREs/EREs
that are empty (or subpatterns that are empty), but, if I remember
correctly, it's simply not part of the grammar given.

Now GNU grep says "The empty regular expression matches the empty string.".
Yet it still matches "foo" in the example above, which clearly is not empty.

So what exactly does "matches the empty string" mean? Only if the line
is completely empty (in which case I still wouldn't understand why foo
matches)? Or does it assume empty strings before/after each character?

Thanks,
Philippe




This bug report was last modified 1 year and 59 days ago.

Previous Next


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