|
From: | Paul Eggert |
Subject: | bug#21414: -F string with tailing newline always matches |
Date: | Fri, 4 Sep 2015 20:45:10 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |