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:
>
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
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
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
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
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
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
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