[OpenWrt-Devel] Question regarding call python script
Bastian Bittorf
bittorf at bluebottle.com
Fri Mar 11 05:51:46 EST 2016
* Paul Fertser <fercerpav at gmail.com> [11.03.2016 11:15]:
> As a sidenote, POSIX shell doesn't support associative arrays (which
> were mentioned in this thread), so it's probably worth clarifying
> whether it's ok to require bash >= 4 for OpenWrt build scripts or not.
yes, POSIX is "missing" some goodies of a full bash but:
"Stick to portable constructs where possible, and
you will make somebody's life easier in the future.
Maybe your own."
For all things you can use a workaround.
So, if you need an array e.g.
foo[7]=bar
for e.g. easy iterating over it? use e.g. this approach:
array_put()
{
local message="$1"
local dim1="$2"
local dim2="$3"
eval ${ARRAYNAME:-default}_${dim1}_${dim2}='$message'
}
array_get()
{
local dim1="$1"
local dim2="$2"
local var
eval var="\"\${${ARRAYNAME:-default}_${dim1}_${dim2}:-unset}\""
echo "$var"
}
array_set "test" 7
array_get 7
or for 2-dimensional arrays:
array_set "2dim" 3 14
array_get 3 14
you can simplify this by removing dim2 and ARRAYNAME if this is too much.
bye, bastian
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list