GNU bug report logs - #8102
[head] do not return EXIT_SUCCESS upon premature EOF

Previous Next

Package: coreutils;

Reported by: Bjartur Thorlacius <svartman95 <at> gmail.com>

Date: Wed, 23 Feb 2011 19:26:02 UTC

Severity: normal

Tags: notabug

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 8102 <at> debbugs.gnu.org (full text, mbox):

From: "Alan Curry" <pacman-cu <at> kosh.dhis.org>
To: svartman95 <at> gmail.com (Bjartur Thorlacius)
Cc: 8102 <at> debbugs.gnu.org
Subject: Re: bug#8102: [head] do not return EXIT_SUCCESS upon premature EOF
Date: Fri, 25 Feb 2011 16:56:28 -0500 (GMT+5)
Bjartur Thorlacius writes:
> 
> On 2/23/11, Eric Blake <eblake <at> redhat.com> wrote:
> > On 02/23/2011 11:58 AM, Bjartur Thorlacius wrote:
> > That's because this is not a bug, but a POSIX requirement:
> >
> > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html
> >
> > "When a file contains less than number lines, it shall be copied to
> > standard output in its entirety. This shall not be an error."
> >
> Indeed. Since it's explicitly mentioned, I assume there's a reason for
> it. I'd be grateful if someone could point out what the rationale beind
> the decision is (or better yet, where such information can be found).
> 
> So should I be using a head-alike for iterating over lines, and would
> such an utility belong to a GNU package, or is awk the right tool for the
> job?

Here's what an iterate-over-lines loop normally looks like in a shell script:

  while read -r line
  do
    something $line
  done

The idea of using head to control a loop means you are either a newbie who
didn't know about "read", or you are trying to do something subtly different
which I didn't understand. Excuse me if I guessed the wrong one.

-- 
Alan Curry




This bug report was last modified 13 years and 209 days ago.

Previous Next


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