Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 05 Jun 2010 14:37:31 -0700
From:      Bakul Shah <bakul@bitblocks.com>
To:        Doug Barton <dougb@FreeBSD.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: head behaviour 
Message-ID:  <20100605213731.816035B30@mail.bitblocks.com>
In-Reply-To: Your message of "Sat, 05 Jun 2010 14:02:16 PDT." <4C0ABB58.6030009@FreeBSD.org> 
References:  <20100605201242.C79345B52@mail.bitblocks.com> <4C0AB448.2040104@FreeBSD.org> <20100605204845.6E56B5B52@mail.bitblocks.com> <4C0ABB58.6030009@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 05 Jun 2010 14:02:16 PDT Doug Barton <dougb@FreeBSD.org>  wrote:
> On 06/05/10 13:48, Bakul Shah wrote:
> > Without running the following can you guess its output?
> >
> > $ look '' | (head -2; head -2)
> 
> Again, it's not clear to me what you expect is going to happen with the 
> second 'head -2' there. I agree that the actual output of your example 
> is wacky and unexpected, but what I'm trying to get you say is what YOU 
> think should happen. The examples that you pasted in your previous post 
> did not and could not do what you said you wanted them to do, so I don't 
> quite understand what the bug is.

There is no bug per se. What I am saying that it would be
*less surprising* if

    $ look '' | (head -2; head -2)

behaved the same as

    $ look '' | head -4

[And yes, I would use head -4 if I wanted four lines but the
example was to illustrate the issue that head buffers more
than it needs to].

It would be less surprising and more useful if

    $ ps | (head -1; grep ssh)

showed

    PID  TT  STAT      TIME COMMAND
    <all line with ssh in it>

The change in head behaviour I am suggesting wouldn't break
anything that already works but make it more useful for what
you call 'wacky commands lines'!

> Put more simply, if you generate wacky command lines you should not be 
> surprised when they produce wacky results. :)

I didn't realize that use of ;(|) constitutes wackiness :-)
They are simply exercising the power of shell!

We have used these commands for so long that we take them for
granted and we learn to avoid their use in such ways.  When
Rob Warnock first mentioned this, my initial reaction was the
same as yours. But thinking more about it, I felt head can be
made more useful with this change and felt it was worth
bringing it to people's attention. But we can let it rest.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100605213731.816035B30>