[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#16329: `head --lines=-0' prints nothing if no newline at the EOF
From: |
Pádraig Brady |
Subject: |
bug#16329: `head --lines=-0' prints nothing if no newline at the EOF |
Date: |
Fri, 03 Jan 2014 17:02:47 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 01/03/2014 04:57 PM, Eric Blake wrote:
> On 01/03/2014 08:50 AM, Алексей Шилин wrote:
>> Hi,
>>
>> If one runs `head --lines=-0 somefile', he'll sometimes get no output
>> instead of full file contents as
>> expected after reading the manual:
>>
>> -n, --lines=[-]K
>> print the first K lines instead of the first 10; with the lead‐
>> ing `-', print all but the last K lines of each file
>>
>> It depends on whether the file has a trailing newline.
>
> Per POSIX, 'head' is only required to operate on "text files"
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html
> and a "text file" must either be empty or have a trailing newline:
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_397
>
> So this is not necessarily a bug. That said, since POSIX doesn't
> specify what we should do, we are free to make it behave differently.
BTW I still don't think POSIX is specifying that text files without
a trailing newline are not text files.
It states that text files can have zero or more lines,
implying that the trailing new line is optional.
thanks,
Pádraig.