On Tue, Feb 8, 2011 at 12:07 PM, Sven-Göran Bergh <[email protected]> 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 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
