After searching the forum, I found that Bash spawns a subshell when using the pipe. I am wondering if there is an option or any other way to turn off this fuctionality.
We are pulling over some scripts from a Korn shell environment. I have found ways to work around looping from a pipe (Thanks to this forum!!), but we would like to not change this logic. We tried to invoke the korn shell (#!/bin/ksh93) environment but found that this version is old and unacceptable.
Just to clarify,
why you don't want to use process substitution (the <(...) syntax)?
Old? KSH-93 is the most recent version of the KornShel Language. It is also most feature-rich implementation of the KornShell. It's currently maintained and continuously improved by its creator David Korn and others at AT&T.
Consider that ksh93 is different from the other shells as far as the last command in a pipeline is concerned (it does not fork a subshell), just like you want it to be.
Consider the following:
You may change this by enclosing the loop and all the following commands with braces for example:
zsh-4.3.9-dev-2[t]% bash -c 'echo OK|{ while read;do ok=$REPLY;done;echo $ok;}'
OK
zsh-4.3.9-dev-2[t]% pdksh -c 'echo OK|{ while read;do ok=$REPLY;done;echo $ok;}'
OK