GNU bug report logs -
#8102
[head] do not return EXIT_SUCCESS upon premature EOF
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8102 in the body.
You can then email your comments to 8102 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Wed, 23 Feb 2011 19:26:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Bjartur Thorlacius <svartman95 <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Wed, 23 Feb 2011 19:26:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
% echo | head -n2 && echo bug
bug
This bit me when writing a line oriented prompter (which would `while
head -n1`).
FYI, this also applies to FreeBSD head.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Wed, 23 Feb 2011 20:17:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 8102 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 02/23/2011 11:58 AM, Bjartur Thorlacius wrote:
> % echo | head -n2 && echo bug
> bug
>
> This bit me when writing a line oriented prompter (which would `while
> head -n1`).
>
> FYI, this also applies to FreeBSD head.
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."
--
Eric Blake eblake <at> redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Fri, 25 Feb 2011 16:41:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 8102 <at> debbugs.gnu.org (full text, mbox):
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?
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Fri, 25 Feb 2011 21:57:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 8102 <at> debbugs.gnu.org (full text, mbox):
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
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Fri, 25 Feb 2011 22:24:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 8102 <at> debbugs.gnu.org (full text, mbox):
tags 8102 + notabug
thanks
Bjartur Thorlacius wrote:
> 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).
Mostly because that is how the tool has always behaved since the first
implementation of the program. Because BSD, System V, GNU (and HP-UX,
IBM AIX, SunOS/Solaris, many others) all implemented it the same way
it was standardized that way for POSIX so that future implementations
would be the same and not break backward compatibility with the
previously existing implementations. After something has been that
way for twenty plus years there often isn't a particular reason other
than if you change it then you break twenty years worth of scripting
that expects it. For many of these the tool came first and then
people documented the existing behavior.
The equivalent to head has always been sed. All of these print the
first five lines of a file:
head -n5
sed -n 1,5p
sed 5q
None of those require five lines or exit with an error code.
Personally I have never thought about that possibility nor needed it.
> 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?
What are you trying to do?
Bob
Added tag(s) notabug.
Request was from
Bob Proulx <bob <at> proulx.com>
to
control <at> debbugs.gnu.org
.
(Fri, 25 Feb 2011 22:24:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Fri, 25 Feb 2011 23:41:01 GMT)
Full text and
rfc822 format available.
Message #22 received at 8102 <at> debbugs.gnu.org (full text, mbox):
On 2/25/11, Bob Proulx <bob <at> proulx.com> wrote:
> Personally I have never thought about that possibility nor needed it.
>
>> 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?
>
> What are you trying to do?
>
Something along the lines of:
% cat bin/prompt
while head -n1 >/dev/tty
do head -n1 </dev/tty
done
% cat prompt/pkg
Some variable
Another variable
% bin/prompt < prompt/pkg | bin/pkg args | paste pre/pkg /dev/stdin post/pkg
> Some variable
< some value
> Another variable
< another value
output value unit
where shell commands are prefixed with '% ', output written to
/dev/tty with '> ' and input read from /dev/tty with '< '. Output
written to stdout and not redirected by the shell is not prefixed.
Although the end of prompt/pkg is reached every time a user inputs a
line after the first `wc -l<prompt/pkg` lines, a SIGPIPE is never sent
as each head process reaches EOF at most once, and exits without
notifying the script. It seems natural to notify about EOF with an
exit status. Instead, I worked around this by passing the length of
stdin in argv, although I could've counted the lines in stdin prior to
prompting (or after printing the first prompt).
The only way I can imagine scripts braking due to head returning
non-zero upon premature EOF are scripts that consider every non-zero
exit fatal, but don't know many lines their input is. How many can
they be?
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#8102
; Package
coreutils
.
(Mon, 28 Feb 2011 06:59:02 GMT)
Full text and
rfc822 format available.
Message #25 received at 8102 <at> debbugs.gnu.org (full text, mbox):
Bjartur Thorlacius wrote:
> The only way I can imagine scripts braking due to head returning
> non-zero upon premature EOF are scripts that consider every non-zero
> exit fatal, but don't know many lines their input is. How many can
> they be?
well, head also returns !=0 e.g. if the file doesn't exist. Therefore,
if a script relies on this, it would fail in the future if head's
behaviour was changed.
Have a nice day,
Berny
bug closed, send any further explanations to
8102 <at> debbugs.gnu.org and Bjartur Thorlacius <svartman95 <at> gmail.com>
Request was from
Jim Meyering <jim <at> meyering.net>
to
control <at> debbugs.gnu.org
.
(Sun, 30 Oct 2011 13:43:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 28 Nov 2011 12:24:02 GMT)
Full text and
rfc822 format available.
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.