home *** CD-ROM | disk | FTP | other *** search
- From: Maarten Litmaath <maart@cs.vu.nl>
-
- In article <1990May21.160437.21491@usenet.ins.cwru.edu> in the newsgroup
- comp.unix.questions, chet@cwns1.CWRU.EDU (Chet Ramey) writes:
- )...
- )I quote (without comment) from P1003.2, draft 9, section 3.12.0.1:
- )
- )"It was decided to allow this extension [running the last process in a
- ) pipeline in the current environment], but not require it; therefore, a
- ) shell programmer should consider a pipeline to be in a subshell environment,
- ) but not depend on it."
- )
- )and from section 3.12:
- )
- )"Additionally, each command of a multi-column pipeline is in a subshell
- ) environment; as an extension, however, any or all commands in a pipeline
- ) may be executed in the current environment."
- )
- )
- )It seems they have already considered this proposal (I imagine David Korn
- )brought it up).
-
- They've considered it indeed, but I don't like the outcome: ambiguity!
- If I write a shell script I want to know *exactly* what'll happen on
- another POSIX system: that's the whole purpose of P1003.2!
- Let's see:
-
- "[...] a shell programmer should consider a pipeline to be in
- a subshell environment, but not depend on it."
-
- What does this buy me? Nothing! What would you think of the following?
-
- "A shell programmer should consider a string beginning with a
- dollar sign to be a shell variable, but not depend on it."
-
- Ridiculous, right? Right.
- My proposal:
-
- If the last command of a pipeline is a (`special') builtin
- command, it must be run in the current environment, else in
- a private environment, just like the other components of the
- pipeline.
-
- In fact I would even accept *every* component that's a (`special')
- builtin command, to run in the current environment, so the following
- would work:
-
- command_1 |
- while read line
- do
- something
- echo "$line"
- last=$line
- done |
- command_2
-
- echo "The last line was: $last"
-
- ...but I realize this could be difficult to implement. On the other hand
- the *last* command in a pipeline is a straightforward case. At that the
- next (well-known) example isn't that obscure at all:
-
- some_command | read answer
-
- In current implementations this won't work as intended. The workarounds
- are ugly, as workarounds often are. (Boy, do I hate temp files.)
-
- OK, but what if the user *wants* a subshell?! Easy, he would use
- parentheses, just like always:
-
- foo=$orig
- another_command | (
- while read foo
- do
- bar
- done
- )
- echo "foo is $foo and should still be $orig"
- --
- Antique fairy tale: Little Red Riding Hood. |Maarten Litmaath @ VU Amsterdam:
- Modern fairy tale: Oswald shot Kennedy. |maart@cs.vu.nl, uunet!cs.vu.nl!maart
-
- Volume-Number: Volume 20, Number 9
-
-