Writing Portable Shell Scripts

The Problem

It is common for students to have portability problems with their scripts when they do their initial development on systems that use bash, for example, as /bin/sh. While bash supports all functionality in the POSIX standard, it also supports a wide range of extended functionality that is not defined by POSIX. When a script is written to use such 'bashisms', it is not guaranteed to run correctly when /bin/sh is some other POSIX compliant shell. On nice.harvard.edu, which is an Ubuntu system, /bin/sh is dash, a shell that runs much faster than bash, but does not support functionality beyond that specified by the POSIX standard. Students who have used 'bashisms' in their scripts discover, often at the last minute, that their scripts will not run under /bin/sh on nice.

The Solution

Here are a few tips to help you avoid such problems: