Ash internal 'read' command and pipes

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Wed Oct 9 11:04:42 UTC 2013


On Wed, 9 Oct 2013, Xabier Oneca  --  xOneca wrote:
>
> I am new here, in the list.
>
> I wonder if 'read' can read from pipes, because the following should
> print 'testing' but instead 'got' remains undefined...
>
>   $ echo testing | read got
>   $ echo $got

In your example, variable $got exists only in a subshell.

Are these examples enough to explain why?

$ { echo main shell >&2; echo testing; } | { read got; echo "subshell: $got" >&2; }; { echo main shell >&2; echo $got; }

This should as you expect it to.

$ read got <<-EOF
	$(echo testing)
EOF
$ echo $got
testing


Cheers,

-- 
Cristian


More information about the busybox mailing list