From: Ralf W. <Ral...@gm...> - 2005-08-02 08:28:24
|
* Richard Purdie wrote on Mon, Aug 01, 2005 at 11:47:16PM CEST: > As things stand there are several bash dependencies in the opcontrol > script. *snip* > With that applied, the only problem is the CHOSEN_EVENTS array. busybox > can't cope with arrays so this presents a problem. I can't see a way to > fix it just using shell variables. You could use eval and set to simulate arrays.. index=3 eval "array_$index=entry" eval "echo \$array_$index" I don't know whether shell special characters (newline included) appear in CHOSEN_EVENTS, but if not, reading out the array entries (unordered) can be done like this in a POSIX-compliant shell: (set) 2>&1 | sed -n 's/^array_[0-9]*=\(.*\)/\2/p' Just a thought. (Autoconf uses a similar construction in its cache saving macros, with additional work for non-POSIX compliant shells.) BTW, instead of writing foo=`echo ${CHOSEN_EVENTS[$f]} | awk -F: '{print $2}'` it's quite a bit faster to use foo=`IFS=:; set x ${CHOSEN_EVENTS[$f]}; echo "$3"` but I don't know whether you care for speed in opcontrol. Also, echo "$foo" | grep ' \.text ' | awk '{print $4}' can be written as echo "$foo" | awk '/ \.text / {print $4}' or even as case $foo in " .text ") (set x $foo; echo "$5");; esac (the latter is admittedly harder to read), and $command if $? = 0; ... as if $command; ... but I don't know if you're interested in such changes. I could produce a patch to this end if you care. Furthermore, if you care, 'seq' is not a POSIX tool, but I don't know if you care about this kind of portability. Cheers, Ralf |