Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: ost on September 29, 2011, 02:53:31 AM

Title: Shell challenge
Post by: ost on September 29, 2011, 02:53:31 AM
This is a general shell question, but since Ive subscribed to this forum I may just ask here.. I hope you don't mind.
Im trying to grab a 2 line output by piping it to two read commands like this:
echo -e "1\n2"|(read l1;read l2)

Now, the l1 and l2 variable doesnt survive the end bracket (sub shell?). What's the easiest way to capture these and pass it to the main shell?

tests:
echo -e "1\n2"|(read l1;read l2;echo -e "$l1\n$l2");#works
echo -e "1\n2"|(read l1;read l2);echo -e "$l1\n$l2";#works not

Title: Re: Shell challenge
Post by: ost on September 29, 2011, 03:12:01 AM
I could add that this is supported in a shell that takes arrays:
line=(`echo -e "1\n2"`)

result:
line=([0]="1" [1]="2")

But microcore's shell doesnt seem to support that.
Title: Re: Shell challenge
Post by: SvOlli on September 29, 2011, 04:02:20 AM
Not nice, but working:
Code: [Select]
eval $(echo -e "1\n2"|(read l1;read l2;echo "l1=\"$l1\" l2=\"$l2\""))To come up with a more sophisticated solution, I need a bigger context.
Title: Re: Shell challenge
Post by: ost on September 29, 2011, 05:13:09 AM
Not nice, but working:

I find it nice and not nice at the same time ;) Thanks :)