bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#41700: grep -v always exiting with 1 for empty file


From: Eric Blake
Subject: bug#41700: grep -v always exiting with 1 for empty file
Date: Thu, 4 Jun 2020 15:34:18 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

On 6/4/20 3:27 PM, Paul Eggert wrote:
On 6/4/20 12:30 PM, Andi Kleen wrote:

in your definition would

echo -n foo > file

(so no newline, but non zero length)

No, the file has zero length:

$ echo -n >file

You missed the 'echo -n foo' that prints 3 bytes to file.

$ ls -l file
-rw-r--r-- 1 eggert eggert 0 Jun  4 13:24 file
have one or zero lines?

Empty files have no lines.

On 6/4/20 1:13 PM, Eric Blake wrote:
The most intuitive behavior is that grep behaves as if the file included the
trailing newline

That's what grep does with files that end in a non-newline byte; such files are
also not text files so POSIX does not specify the behavior.

I answered the question about the 3-byte file. The 0-byte file _IS_ a text file, consisting of zero lines.

But grep, like other
GNU tools, treats empty files as if they contain no lines; this matches most
people's intuition.

POSIX actually requires this behavior for an empty file.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org






reply via email to

[Prev in Thread] Current Thread [Next in Thread]