Can I set up my own sub-environment?

Sven-Göran Bergh sgb at systemasis.com
Tue Feb 8 11:02:48 UTC 2011


> From: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>

> 
> [snip]
> 
> >  -  arrays, does not exists in ash
> 
> But you can generate array lookalike stuf  like this:
> 
>     for i in $(seq 0 9);  do
>         eval foo_$i=$i
>      done
> 
>     for i in $(seq 0 9); do
>          eval bar=\$foo_$i
>          echo foo_$i=$bar
>     done
> 

Sure! But how do find out the number of elements in an "array"?
You need to keep track of that with a separate counter and that
may get cumbersome. An equivalent to the bash parameter expansion
${!foo_*} would have helped but that one is not in ash (nor in
standard).

Consequently, simple array-look-a-likes are possible. Real arrays
are far more than that, escpecially if you want more that one
dimension. The best work around for me is pieces of awk scripts,
but it is certainly not straight forward and messes up things
quickly.

> >  - pushd & popd,  not in ash
> 
> But you can do simple:
> 
>     cd  /foo
>     cd -
> 

This is not the same as pushd and popd. A workaround with aliases
may work though:

~$ alias pushd='wd="$(pwd) ${wd}"; cd'
~$ alias popd='cd ${wd%% *}; wd=${wd#* }'
~$ pushd /etc
/etc$ pushd /home
/home$ pushd /usr
/usr$ popd
/home$ popd
/etc$ popd
~$

That is close to pushd and popd.

> >  - for (( expr1; expr2; expr3  ))..., not in ash
> 
> But a 'while' loop is often a good  replacement.
> 
> >  - parameter expansion, some more in bash than in  ash
> 
> Yes.  But there are ways to get around that too.

See above. ${!foo_*} ???

> 
> >  These are no big obsticles. Once you know about them it is easy to use
> >  alternative solutions.
> 
> Right.
> 
> > What I miss most in ash is  probably arrays.
> 
> See above.

I still miss bash arrays... ;)

Take care
/Sven





More information about the busybox mailing list