如何检查在bash语法,而不运行脚本? [英] How do I check syntax in bash without running the script?

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

问题描述

是否有可能检查bash脚本语法,不执行呢?

使用Perl,我可以运行的perl -c'脚本名称'。是否有任何相当于命令的bash脚本?


解决方案

 庆典-n脚本名

也许一个明显的警告:此验证语法,但如果你的bash脚本试图执行一个命令,是不是在你的路径,如 ECH你好而不是将不检查的回声你好

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 bash scripts?

解决方案

bash -n scriptname

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天全站免登陆