如何在不运行 Bash 脚本的情况下对其进行语法检查? [英] How do I syntax check a Bash script without running it?

查看:23
本文介绍了如何在不运行 Bash 脚本的情况下对其进行语法检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不执行的情况下检查 bash 脚本语法?

Is it possible to check a bash script syntax without executing it?

使用 Perl,我可以运行 perl -c 'script name'.bash 脚本是否有任何等效的命令?

Using Perl, I can run perl -c 'script name'. Is there any equivalent command for bash scripts?

推荐答案

bash -n scriptname

也许有一个明显的警告:这会验证语法,但不会检查您的 bash 脚本是否尝试执行不在您的路径中的命令,例如 ech hello 而不是 echo hello.

Perhaps an obvious caveat: this validates syntax but won't check if your bash script tries to execute a command that isn't in your path, like ech hello instead of echo hello.

这篇关于如何在不运行 Bash 脚本的情况下对其进行语法检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆