From 624defcc20afb68be6edf36ee73ab94163a4a522 Mon Sep 17 00:00:00 2001 From: stepk Date: Thu, 14 Mar 2013 14:17:51 +0100 Subject: [PATCH] fix issue #19 and allow using busybox egrep --- JSON.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/JSON.sh b/JSON.sh index 0d8049e..abc140e 100755 --- a/JSON.sh +++ b/JSON.sh @@ -14,8 +14,11 @@ tokenize () { local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?' local KEYWORD='null|false|true' local SPACE='[[:space:]]+' - egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never | - egrep -v "^$SPACE$" # eat whitespace + { + egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never 2>/dev/null || + egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." # busybox egrep + } | + egrep -v "^$SPACE$" # eat whitespace } parse_array () { @@ -41,6 +44,7 @@ parse_array () { ;; esac [ $BRIEF -ne 1 ] && value=`printf '[%s]' "$ary"` || value= + : } parse_object () { @@ -75,6 +79,7 @@ parse_object () { ;; esac [ $BRIEF -ne 1 ] && value=`printf '{%s}' "$obj"` || value= + : } parse_value () { @@ -86,8 +91,9 @@ parse_value () { ''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;; *) value=$token ;; esac - ! ([ $BRIEF -eq 1 ] && ([ -z $jpath ] || [ "$value" = '' ])) \ + ! ([ $BRIEF -eq 1 ] && ([ -z "$jpath" ] || [ "$value" = '' ])) \ && printf "[%s]\t%s\n" "$jpath" "$value" + : } parse () {