GNU bug report logs - #16329
`head --lines=-0' prints nothing if no newline at the EOF

Previous Next

Package: coreutils;

Reported by: Алексей Шилин <rootlexx <at> mail.ru>

Date: Fri, 3 Jan 2014 16:31:01 UTC

Severity: normal

Merged with 16559, 16560, 16561

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Алексей Шилин <rootlexx <at> mail.ru>
To: 16329 <at> debbugs.gnu.org
Subject: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF
Date: Fri, 03 Jan 2014 19:50:56 +0400
[Message part 1 (text/plain, inline)]
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.

For example:

$ printf '1\n2\n3' > test1
$ printf '4\n5\n' > test2
$ head -n -0 test*
==> test1 <==

==> test2 <==
4
5
$ tail -n +0 test*   # Just for comparison
==> test1 <==
1
2
3
==> test2 <==
4
5
$ 

I'm using Debian GNU/Linux 7 wheezy and coreutils-8.13; I've also tested coreutils-8.22, and it has the
same issue.

A proposed patch fixing the bug is attached. It makes head behave exactly like `tail -n +0' on same files.

-- 
Алексей Шилин
[head_nlines_fix.patch (application/x-patch, attachment)]

This bug report was last modified 11 years and 175 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.