Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!cwns1!chet From: chet@cwns1.CWRU.EDU (Chet Ramey) Newsgroups: comp.unix.questions Subject: Re: Bourne-Shell and fork() (was Re: K-shell variables & Do-loops) Summary: bash does it right Message-ID: <1990Feb23.173445.26325@usenet.ins.cwru.edu> Date: 23 Feb 90 17:34:45 GMT References: <339@ntpdvp1.UUCP> <720013@hpcljws.HP.COM> <642@mwtech.UUCP> <5649@star.cs.vu.nl> Reply-To: chet@po.CWRU.Edu Organization: Case Western Reserve Univ. Cleveland, Ohio, (USA) Lines: 69 In article <5649@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >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... :-( Bash does, however, handle this correctly: cwns1$ { cd /usr/local/bin ; pwd } > foo cwns1$ echo $PWD /usr/local/bin <----- CWD changes for process cwns1$ pwd /usr/local/bin cwns1$ cat foo foo: No such file or directory cwns1$ cd - cwns1$ cat foo /usr/local/bin cwns1$ ksh does this right, too. I would think that with the ability of modern sh's (s5r2 and later) to redirect builtin commands that this would be easy to do. 4.3 BSD /bin/sh is probably a lost cause (maybe CSRG will replace it with bash someday). Perhaps it's because the ability to redirect builtins was added later, while the ability to redirect group commands has been around since V7 -- the group command execution stuff was not updated. All in the name of backwards compatibility. >)... >)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 >) [But not if `cmd' is a shell builtin] >This behavior is RIDICULOUS! A DISGUSTING BUG! Bash gets this right, too (as does ksh): cwns1$ v="initial value" cwns1$ v="new value" builtin type builtin <----- force execution of builtin builtin is a shell builtin cwns1$ echo $v initial value cwns1$ I believe this is a reasonably well-known sh bug that is slated to change. >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. I believe that at least the behavior of {}-grouping *will* change, in response to POSIX.2. Bash is supposed to conform to that spec, so we've tried to implement bash so that it is an example of what will be `standard shell behavior'. Chet Ramey -- Chet Ramey "Can't you pay a grad student to Network Services Group read the manual for you?" Case Western Reserve University -- Bill Wisner, chet@ins.CWRU.Edu to Peter Honeyman