[Top][All Lists]

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

Re: Sub shell mit pipes

From: Enrique Perez-Terron
Subject: Re: Sub shell mit pipes
Date: Wed, 11 Aug 2004 20:33:09 +0200

On Wed, 2004-08-11 at 09:59, Morard Jean-Louis wrote:
> ALL=""
> cat /tmp/text | while read LINE
> do
>         ALL="$LINE $ALL"
>         echo $ALL
> done
> echo "ALL = $ALL"

Is there any formal requirement dictating that the 'while' statement
shall be executed in a sub-shell?

In many programming situations this is awkward, and performance-wise I
cannot imagine it is optimal to do two forks when just one is enough. Of
course, changing will certainly break some existing scripts...

The semantics I would like to see is that in a pipeline, the last
component that is not an external program is executed in the main shell.

I would even prefer the additional rule that if one or more of the
members of a pipeline are statements enclosed in braces ({}), the last
of these is done in the main shell, and only if none of the components
are enclosed in braces the previous rule applies.

Would this create any serious incompatibilities?

If the above has problems, here is another suggestion

commands_1 | exec | commands_2

then main shell will now continue taking its standard input from
commands_1's standard output, and sending its standard output to
command_2's standard input.

Any thoughts?


reply via email to

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