Shell tips and tricks

Ben Scott dragonhawk at gmail.com
Thu Nov 1 15:42:32 EDT 2007


On 11/1/07, VirginSnow at vfemail.net <VirginSnow at vfemail.net> wrote:
> Using "|" is roughly equivalent to doing a fork() and hooking file descriptors
> up so that one process's outputs go to the other process's inputs.

  Right, but doesn't the Process Substitution do a similar thing?  My
question is not "Why does a subshell ever get used at all?", but "Why
is a subshell used sometimes but not others?".  Again, compare these
two:

	foo | while read LINE ; do bar ; i=$(( i + 1 )) ; done

	while read LINE ; do bar ; i=$(( i + 1 )) ; done < <(foo)

  For the second example, the shell has to fork() and exec() the "foo"
program, and hook up it's stdout file descriptor to the stdin file
descriptor that gets passed to the "do clause".  Why doesn't that need
a subshell?

  Or am I misunderstanding your original explanation?

-- Ben


More information about the gnhlug-discuss mailing list