[BusyBox] ash variable dereference

Charles Steinkuehler charles at steinkuehler.net
Thu Aug 8 11:24:03 UTC 2002


> Wow, thanks !!!
>
> Anyone for the sed question, that would become a Good Day !!!

> 2) busybox'sed is limited to numbers for a, i and c commands. Is there
> still a way to use a command to append a line at the end of a file,
like in
> $a\
> //end of file

Do you have to do this with only sed?  Could you maybe use a compound
statement?

Replace:
sed <commands>

With:
( sed <commands> ; echo "//end of file" )

Should work, with the expense of an extra process...if you do this a
lot, you can make the whole thing a shell procedure.

Also, regarding your variable problem, you can also directly evaluate
the variable name, without needing the intermediate "v" variable...ie:

$ ITEM12=HereItIs
$ i=12
$ v=ITEM$i
$ eval result=\$$v
$ echo $result
HereItIs

$ eval result2=\$ITEM$i
$ echo $result2
HereItIs

The ash-specific setvar command can also be used for some similar tricks
(where the variable name is dynamic), at the expense of loosing bash
compatibility...see the ash man page for details on setvar.  The eval
trick will work when either the variable, the value, or both are
dynamic...just remember to watch your character escaping & quoting. :-)

Charles Steinkuehler
http://lrp.steinkuehler.net
http://c0wz.steinkuehler.net (lrp.c0wz.com mirror)




More information about the busybox mailing list