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: Bjartur Thorlacius
Subject: bug#8102: [head] do not return EXIT_SUCCESS upon premature EOF
Date: Fri, 25 Feb 2011 23:40:29 +0000

On 2/25/11, Bob Proulx <address@hidden> 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?





reply via email to

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