...
|: Now this works with some shells, but not with others.
|: (when it doesn't work the variables a and b are not set.)
|: It generally seems to work with the Korn shell, but
|: not with bash and /bin/sh.
|:
|: My guess is that the problem is caused by the `read' command
|: being executed in a subshell.
...
| Cool. 'ls | read a b' works in zsh and ksh, but not in bash or
| sh. I personally don't think it should work anywhere, but that's
| me.
The conventional way to build a pipe, the reader forks the writer.
Hence, if the last item in the pipeline is a shell builtin, it's
natural for it to run in the shell parent process. Almost obtuse
not to, though it does add to the potential for confusion.
... [recommends "set"]
The parsing done by "set" may even work better than "read", on some
old shells like Ultrix /bin/sh that don't handle spaces properly.
If it suits the actual application better to use "read", write the
data to a temporary file, then use "exec" to redirect I/O for the
shell process itself. Then you can read in a loop with no redirection,
and no subprocess even in older shells. The temporary file is quite
efficient, the filesystem will buffer it, so it's not like there's a
lot of overhead in this compared to a pipe.
Donn Cave, University Computing Services, University of Washington