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.
which in itself is a link to a shell interpreter - like bash, ksh, etc. Some popular shell languages are POSIX-compliant (Bash, Korn shell), but even they offer additional non-POSIX features which will not always function on other shells.
You can use POSIX standard in many shells such as, dash , bash , ksh , mksh , yash , zsh , etc.
fish, the friendly interactive shell, is a commandline shell intended to be interactive and user-friendly. fish is intentionally not fully POSIX compliant, it aims at addressing POSIX inconsistencies (as perceived by the creators) with a simplified or a different syntax.
BusyBox is a software suite that provides several Unix utilities in a single executable file. It runs in a variety of POSIX environments such as Linux, Android, and FreeBSD, although many of the tools it provides are designed to work with interfaces provided by the Linux kernel.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With