[Top][All Lists]

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

Re: I think bash logic in a loop like : while [ condition] |read somevar

From: Chet Ramey
Subject: Re: I think bash logic in a loop like : while [ condition] |read somevar is flawed.
Date: Mon, 30 Dec 2013 11:33:43 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1

On 12/30/13 11:22 AM, Suvayu Ali wrote:
> Hi,
> On Thu, Dec 26, 2013 at 06:22:19PM -0500, Chet Ramey wrote:
>> On 12/25/13, 1:33 AM, Pierre Gaston wrote:
>>> If I remember correctly, POSIX allows the lastpipe behaviour.
>> It does, in its usual fashion: "each command of a multi-command pipeline
>> is in a subshell environment; as an extension, however, any or all
>> commands in a pipeline may be executed in the current environment."
> Is there any technical reason to choose one over the other?  Or is it
> not really a choice, and is determined by other limitations of the
> shell?

It simply doesn't work at all in a job control environment; to make that
work requires a fork-on-the-fly-at-the-point-of-suspend strategy and a
lot of ex post facto process group twiddling.  That's way more trouble
than it's worth.

In terms of behavioral consistency, it's a lot easier and more consistent
to say that all components of a pipeline are executed in subshell
environments, and that they do not affect their parent's environment.

There are not that many other technical impediments to running the last
component in the calling shell.  The one you have to pay the most attention
to is making sure that all the pipe file descriptors get closed where they
should, and making sure that all of the other commands in the pipeline get
reaped properly.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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