[Shell] 调试shell脚本的技巧 | 校验shell脚本语法 |寻找匹配的 `"' 是遇到了未预期的文件结束符

 首先准备1个测试shell文件test.sh,内容如下,第2行hello没有用 双隐号括起来(有语法错误)

echo "hello1"
echo "hello

然后在shell脚本所在目录,执行命令:

bash -n test.sh

这个命令是用来检查shell语法格式是否正确

效果如下:

wangju@wangju-HP-348-G4:~/Desktop$ bash -n test.sh
test.sh: line 2: unexpected EOF while looking for matching `"'
test.sh: line 3: syntax error: unexpected end of file

可以看到执行完检查shell语法格式是否正确后,给出我们错误提示信息: unexpected EOF while looking for matching `"'

 

最后修改test.sh,把第2行hello用双隐号括起来(使其没有语法错误)

echo "hello1"
echo "hello"

再次执行bash-n test.sh检查语法,效果如下:

 

 

posted @ 2020-01-03 09:52  wangju003  阅读(5765)  评论(0编辑  收藏  举报