|
|||||||||||
|
Is PR 412: "ksh: command | read produces null/unset variables" a bug?
From: Otto Moerbeek <otto(at)drijf.net>
Date: Sat May 24 2003 - 06:10:56 EDT
PR 412
$ echo 1 2 | read a b
Should print
But as the manual page states, this does not happen with the pd version of ksh. I tried various incarnations of the bourne shell, korn shell and bash on various OSes and all have the same behavior: the last command is executed in a subshell. Digging deeper, I found out that the original (AT&T) ksh has changed with respect to this. Versions prior to the 1988 ksh did execute the last command of a pipe in a subshell. Versions from 1988 and newer do execute the last command in the current environment. See <http://www.kornshell.com/doc/faq.html>, Q13 and M.i. Bolsky and D.G. Korn, The Kornshell Command and Programming Language, 1989, page 190.
Today, a lot of systems (like OpenBSD) use the pd version of ksh, which
cleary states it uses a subshell for the last command in a pipe:
I do not know how the original SysV sh handles this, but I the Open
Group Single Unix Specifications version 2
"Some systems have implemented the last stage of a pipeline in the current environment so that commands such as: command | read foo set variable foo in the current environment. This extension is allowed, but not required; therefore, a shell programmer should consider a pipeline to be in a subshell environment, but not depend on it."
Version 3 of the Single Unix Specifications
"Command substitution, commands that are grouped with parentheses, and asynchronous lists shall be executed in a subshell environment. Additionally, each command of a multi-command pipeline is in a subshell environment; as an extension, however, any or all commands in a pipeline may be executed in the current environment. All other commands shall be executed in the current shell environment." Although the OpenBSD ksh handles pipes differently from more recent versions of the original (AT&T) ksh, I think it makes sense to classify this PR as "not a bug", since the current behavior is allowed by Single Unix and programmers are discouraged to rely on the specific subprocess related behavior of pipes. Furthermore, the current behavior is clearly documented in the man page. -Otto Received on Sat May 24 06:15:45 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:57 EDT |
||||||||||
|
|||||||||||