GNU bug report logs - #21414
-F string with tailing newline always matches

Previous Next

Package: grep;

Reported by: Ian Brown - HNAS <ian.brown <at> hds.com>

Date: Fri, 4 Sep 2015 15:34:03 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

Full log


Message #25 received at 21414 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: ian.brown <at> hds.com, 21414 <at> debbugs.gnu.org, 21414-done <at> debbugs.gnu.org
Subject: Re: bug#21414: -F string with tailing newline always matches
Date: Fri, 4 Sep 2015 21:29:58 -0700
On Fri, Sep 4, 2015 at 8:45 PM, Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> Jim Meyering wrote:
>>
>> I too find this behavior surprising:
>>
>> $ seq 3|grep -F xxx$'\n'
>> 1
>> 2
>> 3
>>
>> This feels like a bug, since it's an artifact of how grep accumulates
>> multiple keys internally: it uses newline as the separator
>> (http://git.savannah.gnu.org/cgit/grep.git/tree/src/grep.c#n2308).
>> Including a literal newline in the search string conflicts with that.
>
>
> It's not an artifact; it's intended behavior.  POSIX says that xxx$'\n'
> (which expands to three 'x's followed by a newline) is a pattern_list, not a
> pattern. A pattern_list is defined to be a series of patterns separated by
> newlines (not terminated by newlines), so that pattern_list has two
> patterns, xxx and the empty pattern.

Thanks for explaining. Looks like I'd better reread that part of the spec.




This bug report was last modified 9 years and 262 days ago.

Previous Next


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