1

I thought that piping from echo was equivalent to here strings, but the REPLY variable of the read builtin command is only set (or in scope I guess) when using here strings:

echo foo | read;echo $REPLY    # prints empty line
read <<<bar;echo $REPLY        # prints "bar"

As sh also only seems to keep read's return variables in scope when using a block such as while, I assume that this is specified by POSIX? What's the motivation for giving different behavior to here strings and how does the shell detect that something is different about the STDIN contents?

0 Answers0