From 9fadb22d40eaba645a962ad8d78499b79ec308f7 Mon Sep 17 00:00:00 2001 From: Janos Gyerik Date: Mon, 3 Nov 2014 22:01:52 +0100 Subject: [PATCH 1/4] replaced deprecated `...` with $(...) --- jsawk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsawk b/jsawk index bb02531..5a76f7d 100755 --- a/jsawk +++ b/jsawk @@ -12,8 +12,8 @@ # licenses of the incorporated software below. # -TMP1=`mktemp /tmp/tmp.XXXXXX` -TMP2=`mktemp /tmp/tmp.XXXXXX` +TMP1=$(mktemp /tmp/tmp.XXXXXX) +TMP2=$(mktemp /tmp/tmp.XXXXXX) trap "rm -f $TMP1 $TMP2" SIGINT SIGTERM SIGHUP SIGQUIT From 95375d85b9570c4d3b5f39f5c900927e9d23e7d2 Mon Sep 17 00:00:00 2001 From: Janos Gyerik Date: Mon, 3 Nov 2014 22:11:38 +0100 Subject: [PATCH 2/4] removed all the pointless -n in [ -n blah ] --- jsawk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jsawk b/jsawk index 5a76f7d..30698ee 100755 --- a/jsawk +++ b/jsawk @@ -1286,10 +1286,10 @@ while getopts :hni:s:j:q:f:b:a:v: opt; do done if [ $get_lines != "no" ]; then - if [ -n "$input_string" ]; then + if [ "$input_string" ]; then # Pass in the input string specified directly echo "$input_string" > $TMP2 - elif [ -n "$input_file" ]; then + elif [ "$input_file" ]; then # Pass in the input file contents specified, first checking the file exists if ! [ -e "$input_file" ]; then echo "Error: Input file cannot be found: $input_file" @@ -1318,8 +1318,8 @@ res=$(cat $TMP2 2>/dev/null | $JSBIN $TMP1 $nlines "$@") out=$(echo "$res" |sed '/^OUT: /s/^.....//p;d') err=$(echo "$res" |sed '/^ERR: /s/^.....//p;d') -[ -n "$err" ] && echo "$err" 1>&2 -[ -n "$out" ] && echo "$out" +[ "$err" ] && echo "$err" 1>&2 +[ "$out" ] && echo "$out" rm -f $TMP1 $TMP2 From 1d96401d7f9d43c67f45129d96ea28ac940187b8 Mon Sep 17 00:00:00 2001 From: Janos Gyerik Date: Mon, 3 Nov 2014 22:13:22 +0100 Subject: [PATCH 3/4] removed a pointless wrapping in echo "$(...)" --- jsawk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsawk b/jsawk index 30698ee..048532b 100755 --- a/jsawk +++ b/jsawk @@ -1298,7 +1298,7 @@ if [ $get_lines != "no" ]; then cat "$input_file" > $TMP2 else # Read input from STDIN - echo "$(cat 2>/dev/null)" > $TMP2 + cat 2>/dev/null > $TMP2 fi nlines=$(grep -c '$' $TMP2 2>/dev/null || echo 0) fi From e5c94c670d456dde1d455d7961bc998f62e5ce8b Mon Sep 17 00:00:00 2001 From: Janos Gyerik Date: Mon, 3 Nov 2014 22:16:28 +0100 Subject: [PATCH 4/4] moved cleanup code to cleanup function --- jsawk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jsawk b/jsawk index 048532b..4b2f4e1 100755 --- a/jsawk +++ b/jsawk @@ -15,7 +15,10 @@ TMP1=$(mktemp /tmp/tmp.XXXXXX) TMP2=$(mktemp /tmp/tmp.XXXXXX) -trap "rm -f $TMP1 $TMP2" SIGINT SIGTERM SIGHUP SIGQUIT +cleanup() { + rm -f $TMP1 $TMP2 +} +trap cleanup SIGINT SIGTERM SIGHUP SIGQUIT cat <<'__END__' > $TMP1 @@ -1321,6 +1324,6 @@ err=$(echo "$res" |sed '/^ERR: /s/^.....//p;d') [ "$err" ] && echo "$err" 1>&2 [ "$out" ] && echo "$out" -rm -f $TMP1 $TMP2 +cleanup exit $ret