Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: <7248@star.cs.vu.nl> Date: 6 Aug 90 16:15:49 GMT References: <1990Aug3.193231.3166@silma.com> <3821@auspex.auspex.com> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 35 In article <3821@auspex.auspex.com>, guy@auspex.auspex.com (Guy Harris) writes: )... )The Bourne shell runs some shell constructs in a sub-shell; apparently, )the construct you gave is one of them. [...] [The construct was ``command | while read line; do something; done''.] )This may change when shells become compliant with POSIX 1003.2, which )will presumably happen sometime after POSIX 1003.2 leaves the draft )stage and is approved; 1003.2 may put stricter controls on when a shell )may do something inside a subshell. I don't have recent drafts handy; )Maarten? I haven't read Draft 10 yet, but I pleaded for the `while' loop from the example to be run in the current shell instead of a subshell (if the user wants a subshell he can always use parentheses). The advantages are obvious. In any case, _redirected_ loops already must be run in the current shell, notwithstanding the current practice in a lot of Bourne shell implementations to create a subshell: var=before while read line do var=after done < file echo var=$var This example will print `after' on POSIX 1003.2 conformant systems, `before' on many current systems. -- "UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." (Doug Gwyn)