相关疑难解决方法(0)

如何语法检查可移植的POSIX shell脚本?

以下shell脚本在/bin/true为第一个参数提供时执行良好,但在执行期间可能会因语法错误而失败!

#!/bin/sh
if $1 ; then exit; fi
/tmp/asdf <<< ASDF # Something with syntax error in POSIX
Run Code Online (Sandbox Code Playgroud)

当然,静态检查可以避免一些语法错误(如果不是全部?)?如何静态检查给定的Shell命令语言脚本是否在语法上有效?

编辑:这个问题中已经回答了检查Bash脚本中的语法错误.

编辑#2:请注意,即使使用和标志执行,Bash也无法正确检查语法是否符合POSIX .+B--posix-n

shell posix static-analysis sh

5
推荐指数
2
解决办法
539
查看次数

标签 统计

posix ×1

sh ×1

shell ×1

static-analysis ×1