Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2013-12-10 21:30:15 +0400
committerJo-Philipp Wich <jow@openwrt.org>2013-12-10 21:30:15 +0400
commite58fa88e1f69557203ddc616bed95b9817c4f7d0 (patch)
treecd9a0b83dd18686761731382257285b87ad64afa /sh
parent318d682d29a8974aa53bd7dc523f1514eb0eddb9 (diff)
jshn: add ability to pass default values to json_get_var and json_get_vars
Diffstat (limited to 'sh')
-rw-r--r--sh/jshn.sh8
1 files changed, 6 insertions, 2 deletions
diff --git a/sh/jshn.sh b/sh/jshn.sh
index 70b7976..85c4151 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -231,13 +231,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
}