Can I set up my own sub-environment?

Denys Vlasenko vda.linux at googlemail.com
Tue Feb 8 11:35:03 UTC 2011


On Tue, Feb 8, 2011 at 12:07 PM, Sven-Göran Bergh <sgb at systemasis.com> wrote:
>> >   - scope of variables (this is a killer!) All variables are global in  ash
>> >    unless declared as local. This goes for functions,  loops, etc.
>>
>> They are global in bash too:
>>
>> $ f() { z=1; }
>> $ echo  $z
>>
>> $ f
>> $ echo $z
>> 1
>>
>> This is how they are supposed to work.  It's not a bug.
>>
>
> Indeed, you are right! I could swear that i had an issue with this when porting
> some stuff from bash a year ago. Anyway, I do no think it is consistent:
>
> $ f1() { for z in $(seq 1 3); do : y=$z; done }
> $ echo "y=$y, z=$z"
> y=, z=
> $ f1
> $ echo "y=$y, z=$z"
> y=, z=3

What is not consistent? ": y=$z" statement is not an assignment.
It's a call to ':' builtin. ':' builtin ignores all its arguments.
So argument y=1 is simply ignored.

Remove ':' and y will be set to 3 after f1 is called.

-- 
vda


More information about the busybox mailing list