Hi,

I've just noticed a somewhat strange behaviour with head(1):

I'm expecting the following to give me the first line of the regular
file "file.in" followed by the rest of the contents sorted.  "file.in"
is a short file with three lines of text.

    (head -n 1; sort) <file.in

However, I only get the first line back on standard output.  Replacing
head with ghead from the GNU coreutils fixes this.  I'm not able to
compare with NetBSD or FreeBSD at this moment.

It's the same behaviour with "sort" replaced by "cat".

I'm assuming it's because head consumes too much of standard input
before exiting (running it in ktrace confirms this).  For a larger file
(over 16kb), the first 16kb are consumed by head while the rest is given
to the next utility in the subshell (sort/cat).

Confusingly, the following works as expected, giving me the first and
last line of the same (small) file:

    (head -n 1; tail -n 1) <file.in

I'm unable to

1) decide if this is a bug in the OpenBSD implementation of head or
if it is expected, and

2) see the principal difference between the two examples.

Regarding 1) The POSIX standard mentions that "When a standard utility
reads a seekable input file and terminates without an error before it
reaches end-of-file, the utility will ensure that the file offset in the
open file description is properly positioned just past the last byte
processed by the utility."

Regards,
Kusalananda

[demime 1.01d removed an attachment of type application/pgp-signature which had 
a name of signature.asc]

Reply via email to