如何在不执行ksh shell脚本的情况下检查其语法的正确性?为了更清晰地说明我的观点:在perl中,我们可以执行命令:
perl -c test_script.pl
想要检查语法,ksh有类似的工具吗?
ksh -n
大多数Borne Shell家族都支持-n选项,包括tcsh。
#!/bin/bash
if [ -f "buggyScript.sh" ; then
echo "found this buggy script"
fi
bash -n buggyScript.sh
缺失的]未被检测到。
第二个测试脚本如下:
#!/bin/bash
if [ -f "buggyScript.sh" ]; then
echo "found this buggy script"
bash -n buggyScript.sh
buggyScript.sh: line 5: syntax error: unexpected end of file
sh -n script
。 它应该有效。 但是,如果您的语法错误在无效的命令名称中,那么只有在运行时才会被捕获。sh -n
仅检查实际的shell语法。 - tripleee