Ash eval wierdness

Paul Smith paul at mad-scientist.net
Wed May 25 15:35:54 UTC 2011


On Wed, 2011-05-25 at 17:20 +0200, Harald Becker wrote:
> In principle you are right, but it depends on the version of bash.
> There exist two strategies which lead to different results in those
> cases. Some shells run the last process in a pipe in the current shell
> others the first process. If the shell runs the first process of a
> pipe, all variable changes done by remaining processes of the pipe are
> lost. If the shell runs the last process of a pipe, variable changes
> in the last process are kept and others are lost.

Is it really the case that there are shells that run the first command
in a pipeline in the current shell?  I've never heard of this.

There are some shells that run the last command in a pipeline in the
current shell: ksh does this for example.  The last time I checked bash
does NOT do this, although maybe this was added in the latest versions?
I don't remember if zsh does this or not.

All other shells I'm aware of fork _all_ the commands in the pipeline.

Either method is acceptable from the standpoint of POSIX, so no shell
script that uses #!/bin/sh should ever depend on the "ksh behavior".

I agree it's a shame because it is so often useful to preserve variables
in the final command.  But, that's the way it is and it seems unlikely
to change.



More information about the busybox mailing list