Skip to content

Commit 34f62be

Browse files
committed
Implement syntax check for AWK
This works by letting `mawk`/`gawk` read the script but directly terminate when the script starts.
1 parent 016e81d commit 34f62be

File tree

1 file changed

+6
-1
lines changed
  • sql/files/defaultdata/awk

1 file changed

+6
-1
lines changed

sql/files/defaultdata/awk/run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ DEST="$1" ; shift
1313
MEMLIMIT="$1" ; shift
1414
MAINSOURCE="$1"
1515

16-
# There is no portable way to test the syntax of an awk script.
16+
# Syntax check based on: https://stackoverflow.com/a/7212314
17+
for j in "$@" ; do
18+
awk -f $j -- 'BEGIN { exit(0) } END { exit(0) }'
19+
EXITCODE=$?
20+
[ "$EXITCODE" -ne 0 ] && exit $EXITCODE
21+
done
1722

1823
# We construct here the list of source files to be passed to awk:
1924
FILEARGS=''

0 commit comments

Comments
 (0)