$I'm perplexed. I can't get read to take input from a pipe.
$Why? Does it matter that read is an internal command?
Yes, indeed it does. When you say foo | read bar, the "read bar"
is a separate shell from the one controlling the entire job. It does,
in fact, read the output of foo into a variable called bar, but the
bar is in the second shell. It gets run as follows:
/bin/sh (at whose prompt you type 'foo | read bar')
foo =====(stdout)=====>=====(stdin)===== /bin/sh -c "read bar"
And of course, the second shell goes away when the command is
A quick and inelegant solution is
foo > /tmp/foo$$
read bar < /tmp/foo$$
One other that I tried on Xenix was
read bar << EOF
In fact, the output of the command foo does get put into the here
document, but the shell complains that it is unable to read it and
no value is read into bar. For all I know, this may work on other
*nix flavours, but don't count on its portability if it does.
|I know that sometimes my jaw clicks when I eat. Void where prohibited.|
|Have you seen this boy? Lust never sleeps. I say hurl. Honey, I'm |