How do I syntax check a Bash script without running it?

前端 未结 8 655
渐次进展
渐次进展 2020-11-28 00:16

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 ba

8条回答
  •  旧巷少年郎
    2020-11-28 00:50

    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.

提交回复
热议问题