help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Why using head in different ways will not terminate in t


From: Pierre Gaston
Subject: Re: [Help-bash] Why using head in different ways will not terminate in the same time?
Date: Sun, 27 Mar 2016 12:39:32 +0300

On Sun, Mar 27, 2016 at 7:50 AM, Ehsan Hajiramezanali <
address@hidden> wrote:

> Hi
>
> The following way of calling `head` will terminate as soon as possible:
>
> head -n 1 <(echo 1; sleep 10; seq 10)
>
> However, the original command using the following pipeline does not
> work as what I want, i.e. `head` will wait until `sleep` is finished.
>
> (echo 1; sleep 10; seq 10) | head -n 1
>
> It only needs the output from the first echo command. It is
> unnecessary that it waits until `sleep` is finished. I am wondering
> if this problem is related with the shell or the other things.
>
> Thanks in advance.
>
> Best regards,
> Ehsan
>
>
It's not really a problem, it's just the way the shell is implemented.

In the second case the shell waits for the whole pipeline to exit before
going on.
When the right hand side exits nothing happens to the left hand side until
it tries to write to the pipe in which case it will receive "SIGPIPE"

.


reply via email to

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