如何测试Shell脚本以验证它是否符合POSIX?我有大量的脚本为各种版本的Bash和可能的其他Shell编写.我希望能够确定哪些完全符合POSIX,哪些不符合POSIX.理想情况下,我想找到类似lint的东西,但要用于shell脚本.
How can I test a shell script to verify that it is POSIX compliant? I have a large set of scripts written for various versions of Bash and possibly other shells. I'd like to be able to determine which are fully POSIX compliant and which are not. Ideally, I'd like to find something like lint but for shell scripts.
推荐答案无法静态验证脚本是否符合POSIX,因为差异不限于语法更改,而某些差异只是更改某些命令的行为方式.此链接描述了bash和POSIX之间的区别标准.
It's not possible to statically verify if a script is POSIX compliant because the differences are not restricted to syntax changes and some differences simply changes the way some commands behave. This link describes the differences between bash and POSIX standard.
但是,您可以使用bash --posix ./your_script.sh或在其中使用set -o posix来显式检查运行的脚本.
However, you can explicitly check your scripts running then with bash --posix ./your_script.sh or using set -o posix inside them.
更多推荐
测试POSIX Shell的合规性?
发布评论