Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for POSIX shell compliance?

Tags:

shell

posix

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.

like image 818
Present Occupant Avatar asked Feb 22 '15 05:02

Present Occupant


People also ask

What shells are POSIX compliant?

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.

Is bash POSIX compliant?

You can use POSIX standard in many shells such as, dash , bash , ksh , mksh , yash , zsh , etc.

Is Fish shell POSIX compliant?

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.

Is BusyBox POSIX compliant?

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.


1 Answers

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.

like image 106
Marcelo Cerri Avatar answered Nov 15 '22 13:11

Marcelo Cerri