X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=sh%2Fjshn.sh;h=06ba96535b22045c84abe066d1a62b875b90f90c;hb=39a8fae44186c074265482a09eaa8465334f8183;hp=70b7976e55468c2aabf85c8592cdf28caaf89e29;hpb=318d682d29a8974aa53bd7dc523f1514eb0eddb9;p=project%2Flibubox.git diff --git a/sh/jshn.sh b/sh/jshn.sh index 70b7976..06ba965 100644 --- a/sh/jshn.sh +++ b/sh/jshn.sh @@ -103,7 +103,7 @@ json_set_namespace() { } json_cleanup() { - local unset + local unset tmp _json_get_var unset JSON_UNSET for tmp in $unset JSON_VAR; do @@ -206,6 +206,7 @@ json_get_keys() { json_get_values() { local _v_dest="$1" local _v_keys _v_val _select= + local _json_no_warning=1 unset "$_v_dest" [ -n "$2" ] && { @@ -231,13 +232,17 @@ json_get_var() { _json_get_var __cur JSON_CUR local __var="${JSON_PREFIX}${__cur}_${2//[^a-zA-Z0-9_]/_}" - eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]" + eval "export -- \"$__dest=\${$__var:-$3}\"; [ -n \"\${$__var+x}\${3+x}\" ]" } json_get_vars() { while [ "$#" -gt 0 ]; do local _var="$1"; shift - json_get_var "$_var" "$_var" + if [ "$_var" != "${_var#*:}" ]; then + json_get_var "${_var%%:*}" "${_var%%:*}" "${_var#*:}" + else + json_get_var "$_var" "$_var" + fi done } @@ -263,7 +268,8 @@ json_select() { _json_set_var JSON_CUR "$cur" ;; *) - echo "WARNING: Variable '$target' does not exist or is not an array/object" + [ -n "$_json_no_warning" ] || \ + echo "WARNING: Variable '$target' does not exist or is not an array/object" return 1 ;; esac