Thursday, April 3, 2008

Pipelines Create Subshells: A Demo

Pipelines create subshells. This example shows that each end of the pipeline is in a subshell
$ x=42
$ x=6 | x=9
$ echo $x
42 
If you want to be fancier,
$ x=42
$ { echo $x>/dev/tty; x=6; } | { echo $x>/dev/tty; x=9; }
42
42
$ echo $x 42 

No comments: