Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bash improvements #37

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions jsawk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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