Can I set up my own sub-environment?
Sven-Göran Bergh
sgb at systemasis.com
Tue Feb 8 11:07:10 UTC 2011
> From: Denys Vlasenko <vda.linux at googlemail.com>
...
> > > It seems to me that the syntax for functions in ash and bash is
different
> > > and incompatible.
> > >
> >
> > Ash is certainly not bash and you should not expect every
> > bash corner to be there. If you do you are in for some
> > surprises. Just from top of my head there are at least
> > these differences (probably a lot more):
> > - functions, as you mention. However, you can make them like:
> > test() {echo hello} # skip "function"
> > - arrays, does not exists in ash
> > - pushd & popd, not in ash
> > - for (( expr1; expr2; expr3 ))..., not in ash
> > - parameter expansion, some more in bash than in ash
>
> All of these are not in
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
> either.
Yes, I know. I only referred to the differences betweeen ash and bash in order
to help a bash guy not to get burned.
>
> > - 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
Brgds
/Sven
More information about the busybox
mailing list