Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Bourne-Shell and fork() (was Re: K-shell variables & Do-loops) Message-ID: <5649@star.cs.vu.nl> Date: 22 Feb 90 23:15:13 GMT References: <339@ntpdvp1.UUCP> <720013@hpcljws.HP.COM> <642@mwtech.UUCP> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatika, Amsterdam, the Netherlands Lines: 45 In article <642@mwtech.UUCP>, martin@mwtech.UUCP (Martin Weitzel) writes: )... ){ cd somewhere; morestuff;} > whatever # sh now forks!! working directory )morecommands # doesn't change for process executing morecommands Too bad... :-( Now we need something gross like the following to redirect the output to another file temporarily: exec 3>&1 > file # remember the original stdout in file # descriptor 3, connect stdout to `file' some_stuff exec 1>&3 3>&- # reconnect stdout to the original file, # close fd 3 )... )v="initial value" )v="new value" cmd # v is set to "new value" only in the environment of cmd )nextcommand $v # and $v expands to "initial value" here ) )This is well-known behaviour. But what, if cmd is executed internally? )I think you guessed it -- now $v expands to "new value" when executing )nextcommand. The following fragment of a script makes use of this: ) )x=external )x=internal pwd >/dev/null )echo "pwd is an $x command in this version of the shell" This behavior is RIDICULOUS! A DISGUSTING BUG! When a `normal' command is made into a built-in, redirection mustn't change its behavior. Likewise it shouldn't make any difference if a command is a function or an executable. )... )BTW: I would not be surprised, if the behavior of {}-command grouping )and loops with redirection will change in the future ... so don't )depend on it. If the behavior of {}-grouping and loops with redirection were to change, it would break some scripts. Considering the gain in elegance I wouldn't object though. -- "Ever since the discovery of domain addresses in the French cave paintings [...]" (Richard Sexton) | maart@cs.vu.nl, uunet!mcsun!botter!maart