bug-coreutils
[Top][All Lists]
Advanced

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

bug#8231: Bug in the linux command: tail


From: Roger N. Clark
Subject: bug#8231: Bug in the linux command: tail
Date: Fri, 11 Mar 2011 13:29:08 -0700
User-agent: Mozilla/5.0 (X11; U; HP-UX ia64; en-US; rv:1.7.12) Gecko/20051024

Eric Blake wrote:
On 03/11/2011 10:03 AM, Roger N. Clark wrote:

Tail with a line count option with multiple files fails.

For example:

tail -3 foo.txt
f
d
s

works, but

tail -3 foo.txt  csh.cshrc
tail: option used in invalid context -- 3


Thanks for the report.  At first, I was about to claim that this is not
a bug in GNU coreutils, but a difference in levels of POSIX compliance.

But digging further shows this in the NEWS file:  Back in coreutils 5.90:

** Bring back support for `head -NUM', `tail -NUM', etc. even when
  conforming to POSIX 1003.1-2001.  The following changes apply only
  when conforming to POSIX 1003.1-2001; there is no effect when
  conforming to older POSIX versions.
    tail -[NUM][bcl][f] [FILE]

Basically, POSIX 2001 and newer does _not_ require -3 to be parsed as a
valid option (rather, the POSIX spelling is -n -3), so GNU coreutils is
supporting -3 as an extension.

Then I looked at the actual POSIX 2008 wording:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/tail.html

    tail [-f] [-c number|-n number] [file]

That is, POSIX states that it is only portable to supply at most one
filename, so the fact that GNU tail can support multiple files is
already an extension, whether or not you also mix in the GNU extension
of supporting -3 as an option.

You can work around it by using: 'tail -n -3 file1 file2'


This works on HP-UX.


Since we're already dealing with two GNU extensions, I don't see why we
can't be nice and make the shorter syntax work the way HP-UX is doing
things.  Patches welcome!


Eric,

Thank you for the quick reply.  I'm fine with needing to say -n -3.
Perhaps the man page needs to be clearer, so should be changed from the current:

       -n, --lines=N
              output the last N lines, instead of the last 10

to something like:

       -n N, --lines=N
              output the last N lines, instead of the last 10

A test showed no difference between -n -3 and -n 3.

Thanks!
Roger






reply via email to

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