Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!ames!nrl-cmf!cmcl2!rutgers!njin!princeton!mccc!jonlab!jon From: jon@jonlab.UUCP (Jon H. LaBadie) Newsgroups: comp.unix.questions Subject: Re: what's the use of "{ list }" in /bin/sh? Summary: Not accurate, with redirection does fork [ LONG? ] Message-ID: <451@jonlab.UUCP> Date: 9 Jul 88 05:53:29 GMT References: <23590@teknowledge-vaxc.ARPA> <409@fmeed1.UUCP> <11755@agate.BERKELEY.EDU> Organization: 4455 Province Line Rd., Princeton, NJ 08540 Lines: 63 In article <11755@agate.BERKELEY.EDU>, ked@garnet.berkeley.edu (Earl H. Kinmonth) writes: > >{ > > echo "This is an example of how" > > echo "one can use the { list } " > > echo "construct to re-direct the" > > echo "output of several commands." > > date > > who > >} >$HOME/test.log > > > > It should be noted that for this purpose { } has the advantage of > NOT forking another shell unlike ( ) used in the same manner. This would be true except for the use of redirection. The example will fork a child shell, effectively making { } and ( ) the same. Note, this is not true of the Korn shell. An example to demonatrate the effect. x="The quick brown fox" echo "Before block 1: $x" # not redirected { echo "Starting block 1: $x" x="jumped over the lazy dogs back" echo "Leaving block 1: $x" } echo "After block 1: $x" echo x="The quick brown fox" echo "Before block 2: $x" # redirected { echo "Starting block 2: $x" x="jumped over the lazy dogs back" echo "Leaving block 2: $x" } > /dev/tty echo "After block 2: $x" If a procedure stays in a single shell, then variables changed in the blocked commands will also be changed after the block. If on the other hand, the block is executed in a child process (after a fork), neither changed variables (nor changed directories) will be reflected by the parents environment. Using the Bourne shell, the output of this script is: Before block 1: The quick brown fox Starting block 1: The quick brown fox Leaving block 1: jumped over the lazy dogs back After block 1: jumped over the lazy dogs back Before block 2: The quick brown fox Starting block 1: The quick brown fox Leaving block 1: jumped over the lazy dogs back After block 2: The quick brown fox -- Jon LaBadie {att, ulysses, princeton}!jonlab!jon