ash while loops and variable scope

Denys Vlasenko vda.linux at googlemail.com
Sat Sep 4 19:39:10 UTC 2010


On Sat, Sep 4, 2010 at 1:39 AM, Stuart Longland <redhatter at gentoo.org> wrote:
> In some other parts, I've used constructs like
>
> for var in $( foo ); do
>        blah
> done
>
> but that doesn't work in the above case since listener-prog returns one
> entry per line.  The difference in terms of variables being set inside
> the for loop I guess is that there are no pipes involved... $( foo )
> gets evaluated, then that is passed to the for loop.  I could of course
> change it to ensure each event has no spaces in it, and then for loops
> would quite successfully in that case.

Wouldn't work if you want foo to run in parallel with the for loop.
`cmd` is evaluated before for loop starts. And "evaluated" here means
"run cmd *until* it* exits* and collect its stdout".

>> while read event; do
>>       case "${event}" in
>>               EVENT_A)
>>                       evt_a_seen=1
>>                       ;;
>>               EVENT_B)
>>                       evt_b_seen=1
>>                       ;;
>>       esac
>> done < <(listener-prog)
>
> This method looks interesting too... however...
>
> On 09/03/10 18:11, Bob Dunlop wrote (describing the same technique):
>> Unfortunately Ash doesn't support named pipes.  I think Zsh also supports
>> named pipes if you have that available.

Named pipes require a place in the filesystem where to create
these named pipes. Older versions of bash were creating them in /tmp
and forgetting to delete them afterwards. Ugly.
Newer bash seems to use /proc/PID/fd/NNN.
Need to investigate hot it does that.

> I take it the "<(foobar)" is a form of named pipe?  I see I've got
> plenty of reading to do. :-)

"cmd <(foobar)" will be replaced by "cmd FILENAME" where FILENAME
is a name of a named pipe. foobar will be run as a child of shell, writing
to that pipe.
Thus, "cmd <<(foobar)" will be replaced by "cmd <FILENAME"
and cmd will read from that pipe.

> On 09/04/10 02:21, Harald Becker wrote:
>> There exists a man page for ash, try google with "ash manpage" or use
>> the following link:
>>
>> http://linux.die.net/man/1/ash
>>
>> But keep in mind, there are a few differences between real ash and the
>> version included in busybox ... look ahead for another mail to this topic.
>
> That link is one I intend to have a look at... is there somewhere that
> describes the 'Busybox ash' scripting language?  I know there'll be
> differences, ash in Busybox implements some bash features but not all,

Yes.

> and I'd imagine there are some ash features that are missing in Busybox
> ash.

No. IIRC most active ash development nowadays is in busybox ash.

-- 
vda


More information about the busybox mailing list