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

2020-06-04 Thread Norihiro Tanaka
On Wed, 3 Jun 2020 20:26:41 -0700 Andi Kleen wrote: > > % grep --version > grep (GNU grep) 3.4 > ... > % echo -n > foo > % grep -v foo foo ; echo $? > 1 > > Would expect it to exit with zero in this case, since foo is not in the > file. > > When the file is one byte it works as expected: >

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

2020-06-04 Thread Andi Kleen
On Thu, Jun 04, 2020 at 07:26:34PM +0900, Norihiro Tanaka wrote: > > On Wed, 3 Jun 2020 20:26:41 -0700 > Andi Kleen wrote: > > > > > % grep --version > > grep (GNU grep) 3.4 > > ... > > % echo -n > foo > > % grep -v foo foo ; echo $? > > 1 > > > > Would expect it to exit with zero in this case

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

2020-06-04 Thread Paul Eggert
On 6/4/20 7:06 AM, Andi Kleen wrote: > I would argue that a empty file has a single empty line. No, an empty file has no lines. A single empty line would be a file of size 1, containing just a newline byte. > Besides it completely breaks the "is foo not in file" functionality. That's not what -v

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

2020-06-04 Thread Andi Kleen
On Thu, Jun 04, 2020 at 12:19:14PM -0700, Paul Eggert wrote: > On 6/4/20 7:06 AM, Andi Kleen wrote: > > I would argue that a empty file has a single empty line. > > No, an empty file has no lines. A single empty line would be a file of size 1, > containing just a newline byte. Just out of curiosi

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

2020-06-04 Thread Eric Blake
On 6/4/20 2:30 PM, Andi Kleen wrote: Just out of curiosity, in your definition would echo -n foo > file [side point: echo -n is not portable, printf is better] (so no newline, but non zero length) have one or zero lines? Neither. Per POSIX, a non-empty file that does not end in newline i

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

2020-06-04 Thread Paul Eggert
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 $ 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

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

2020-06-04 Thread Eric Blake
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

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

2020-06-04 Thread Paul Eggert
On 6/4/20 1:34 PM, Eric Blake 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. Ah sorry, indeed I did. In that case my