Is it possible to check a bash script syntax without executing it?
Using Perl, I can run perl -c 'script name'
. Is there any equivalent command for bash scripts?
Is it possible to check a bash script syntax without executing it?
Using Perl, I can run perl -c 'script name'
. Is there any equivalent command for bash scripts?
I actually check all bash scripts in current dir for syntax errors WITHOUT running them using
find
tool:Example:
find . -name '*.sh' -exec bash -n {} \;
If you want to use it for a single file, just edit the wildcard with the name of the file.
Run this. If there are any syntax errors in the script, then it returns the same error message. If there are no errors, then it comes out without giving any message. You can check immediately by using
echo $?
, which will return0
confirming successful without any mistake.It worked for me well. I ran on Linux OS, Bash Shell.