diff --git a/jsawk b/jsawk index bb02531..4b2f4e1 100755 --- a/jsawk +++ b/jsawk @@ -12,10 +12,13 @@ # 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 +cleanup() { + rm -f $TMP1 $TMP2 +} +trap cleanup SIGINT SIGTERM SIGHUP SIGQUIT cat <<'__END__' > $TMP1 @@ -1286,10 +1289,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" @@ -1298,7 +1301,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 @@ -1318,9 +1321,9 @@ 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 +cleanup exit $ret