[X-Unix] Bad behavior of 'head', etc., in reading pipes.

Aaron aaron at macuser.fastmail.fm
Fri Sep 5 05:37:40 PDT 2008


The following observation has been verified by me only with tcsh, so I'd be curious to know if it occurs with other shells.

I executed a number of variants of the command line:

	cat input_file | ( head -c NUM1 >! testfile; head -c NUM2 )

In each case, instead of the output of the second 'head' beginning right after where the first 'head' left off, it always begins at the next offset (from the start of input_file) that's a multiple of 16KB.

Variants tested include reading a number of lines rather than characters and using the command 'od' in place of 'head'.

But with the command line:

	( head -c NUM1 >! testfile; head -c NUM2 ) < input_file

a similar thing happens, except that the offset for the second read is the next multiple of 4KB, not 16KB.

Is this a problem with the way 'head' and 'od' read from the standard input, or is it a limitation of the way pipes and redirects are implemented, at least when created by tcsh?


More information about the X-Unix mailing list