Considering that POSIX is the closest thing to a common standard among all unices, I'm interested in knowing if there's a shell that supports it exclusively. While most modern shells provide support for POSIX (and will run POSIX compliant scripts without any problem), they don't do a good job at pointing out non compliant features.
Is there any shell that implements POSIX and POSIX only, in such a way that it'd throw an error for any non compliant feature?
EDIT I want to clarify that I'm not asking for general tips for writing portable shell scripts. The related question mentionned in the comments already covered this. I thought of this question when I found out that bash
has a --posix
option but only to discover that it only affects some intialization behaviors which is not exactly what I'm looking for.
Best Answer
Unfortunately, 'portable' is usually a stronger requirement than 'POSIX-compliant' for shell scripts. That is, writing something that runs on any POSIX shell isn't too hard, but getting it to run on any real-world shell is harder.
You can start by installing every shell in your package manager, in particular debian's
posh
sounds like what you want (Policy-compliant Ordinary SHell). Debian's policy is POSIX with a few exceptions (echo -n
specified,local
...).Beyond that though, testing has to cover a few shells (/bin/sh especially) on a range of platforms. I test on Solaris (/bin/sh and xpg4/sh), and BSD. AIX and HP-UX are very compliant and don't cause problems. bash is a little world of its own.
I'd recommend the Autoconf guide to portable shell, which is absolutely brilliant and saves a lot of time. Large chunks of it are obsolete, but that's OK; just skip TruUnix and Ultrix and so on if you don't care!