diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-09-11 13:40:22 +0400 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-09-11 13:40:22 +0400 |
commit | a1a97eb11e89c420b84a659a88a4e72c7f04367d (patch) | |
tree | 84b59196eb39fe845f182d88d0b34efef14db265 /sh | |
parent | dee81b4f7902c5b59654f4e8fdbb153bb4f67c62 (diff) |
jshn: support using characters in elements that do not conform to shell variable restrictions
Diffstat (limited to 'sh')
-rw-r--r-- | sh/jshn.sh | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -19,11 +19,15 @@ json_add_generic() { local val="$3" local cur="${4:-$JSON_CUR}" - [ "${cur%%[0-9]*}" = "JSON_ARRAY" ] && { + if [ "${cur%%[0-9]*}" = "JSON_ARRAY" ]; then eval "local aseq=\"\${SEQ_$cur}\"" var=$(( ${aseq:-0} + 1 )) export -- "SEQ_$cur=$var" - } + else + local name="$(echo -n "$var" | tr -C '[a-zA-Z_]' _)" + [[ "$name" == "$var" ]] || export -- "NAME_${cur}_${name}=$var" + var="$name" + fi export -- "${cur}_$var=$val" export -- "TYPE_${cur}_$var=$type" |