Test for POSIX shell compliance?

2019-04-07 00:33发布

问题:

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.

回答1:

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.

However, you can explicitly check your scripts running then with bash --posix ./your_script.sh or using set -o posix inside them.



标签: shell posix