POSIX Shell (sh)

POSIX, known as Portable Operating System Interface, is a standard UNIX shell interface. Unlike BASH, POSIX shell script is executable across different shell like DASH, KornShell, etc. Hence, the portability is there. The caveat however, is that POSIX shell is limited to a certain of syntaxes and executables to use.

POSIX Compliance Priority

Unlike BASH, POSIX Shell has a priority to be portable across different UNIX system including MacOS. Ideally, it is recommended for you to test your script across all the targeted machines, especially MacOS since they do not implement GNU shell natively.

Hence, your priority for scripting is:

  • Functions and Features
  • Portable across different shells
  • Portable across different operating system

Decision on BASH or POSIX

This section covers only POSIX compliant shell. Hence, we consider a minimum of few shell considerations:

  • Use POSIX when you need to run the script first in a fresh install Unix environment.
  • Use BASH when you want to write the script as a program (POSIX is limited by its features).
  • Use BASH if you want to use all the BASH advanced feature.

BASH specific features is available in my BASH guide.

Once you're ready, you may proceed to the sub-sections via the navigation bar. Please enjoy!