Ash internal 'read' command and pipes

Xabier Oneca -- xOneca xoneca at gmail.com
Wed Oct 9 11:48:12 UTC 2013


So pipes are executed in a subshell then? I though all remained in the
same shell... Indeed, I have just tested in Bash and behaves the same
(my surprise!)

Well... at least I know my script can work, but wrapping some lines in
curly braces.

Thank you so much, Cristian!

--
xOneca_,,_


2013/10/9 Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>:
> 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
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list