[buug] loops and pipe sinks are subshells, aaaargh
itz at buug.org
Thu Aug 4 14:07:14 PDT 2011
> matica:~$ echo bar > baz
> matica:~$ foo=1
> matica:~$ cat baz | while read line ; do foo=$line ; done
> matica:~$ echo $foo
Tony> Well, a pipe does need two processes so you can have concurrent
Tony> execution, otherwise you'd have a MSDOS-style pipe
But bash creates 3 processes in this case. There is a subshell where
the while .. done executes. And I'm sure this is mandated by POSIX.
Anyway, as I wrote I'm just interested in solutions :-P Right now I use
temporary files which is ugly as sin.
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD
Rule 420: All persons more than eight miles high to leave the court.
More information about the buug