bug-coreutils
[Top][All Lists]
Advanced

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

bug#8102: [head] do not return EXIT_SUCCESS upon premature EOF


From: Alan Curry
Subject: 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 <address@hidden> 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





reply via email to

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