Ash internal 'read' command and pipes

Tito farmatito at tiscali.it
Wed Oct 9 12:05:46 UTC 2013


On Wednesday 09 October 2013 13:48:12 Xabier Oneca -- xOneca wrote:
> 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

Hi,
also this works at least on bash.

echo testing | while  read  line
> do
> echo $line
> done
testing

ciao,
Tito


More information about the busybox mailing list