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

前端 未结 8 675
渐次进展
渐次进展 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:55

    sh  -n   script-name 
    

    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 return 0 confirming successful without any mistake.

    It worked for me well. I ran on Linux OS, Bash Shell.

提交回复
热议问题