首先准备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检查语法,效果如下:

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

 

 

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-02-19
  • 2022-01-12
  • 2021-06-07
  • 2022-02-06
  • 2022-01-09
猜你喜欢
  • 2022-02-19
  • 2021-12-19
  • 2022-02-02
  • 2022-12-23
  • 2021-12-27
  • 2021-12-28
相关资源
相似解决方案