[OpenWrt-Devel] Question regarding call python script
Karl Palsson
karlp at tweak.net.au
Sat Mar 12 17:43:34 EST 2016
Bastian Bittorf <bittorf at bluebottle.com> wrote:
> * 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.
You know, this is _exactly_ why people want to use python or even
perl instead of bash/awk/sed.
This is a great, wonderful solution if you _must_ use posix
shell. But do we?
Cheers,
Karl P
-------------- next part --------------
_______________________________________________
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