On 12/03/2016 23:43, Karl Palsson wrote: > > Bastian Bittorf <bitt...@bluebottle.com> wrote: >> * Paul Fertser <fercer...@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 >
we are discussing solutions to a problem here that we dont even know. personally i believe that if you need to use arrays in bash hen the solution might not be the best. could whoever wants to use arrays please explain what he wants to do in the target folder that requires arrays ? once we understand the problem we can discuss if arrays are required. discussing awk vs perl vs bash vs python without any context apart from some snippets posted by basti seems suboptimal. John _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel