From a1a97eb11e89c420b84a659a88a4e72c7f04367d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 11 Sep 2011 11:40:22 +0200 Subject: jshn: support using characters in elements that do not conform to shell variable restrictions --- sh/jshn.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sh') diff --git a/sh/jshn.sh b/sh/jshn.sh index 7389f8c..8ecefcf 100644 --- a/sh/jshn.sh +++ b/sh/jshn.sh @@ -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" -- cgit v1.2.3