Are there any AWK syntax checkers? I’m interested in both minimal checkers that only flag syntax errors and more extensive checkers along the lines of lint.
It should be a static checker only, not dependent on running the script.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you prefix your Awk script with
BEGIN { exit(0) } END { exit(0) }, you’re guaranteed that none of your of code will run. Exiting duringBEGINandENDprevents other begin and exit blocks from running. If Awk returns 0, your script was fine; otherwise there was a syntax error.If you put the code snippet in a separate argument, you’ll get good line numbers in the error messages. This invocation…
Gives error messages like this:
GNU Awk’s
--lintcan spot things like global variables and undefined functions:And GNU Awk’s
--posixoption can spot some compatibility problems:Update:
BEGINandENDAlthough the
END { exit(0) }block seems redundant, compare the subtle differences between these three invocations:In Awk, exiting during
BEGINwill cancel all other begin blocks, and will prevent matching against any input. Exiting duringENDis the only way to prevent all other event blocks from running; that’s why the third invocation above shows that no print statements were executed. The GNU Awk User’s Guide has a section on theexitstatement.