trevcan@internets /dev/human $

The Usual Linux Problems

Posted on: 05/19/22 23:14:03
Last edited: 05/19/22 23:14:46

Most of the time, it boils down to RTFM [1]!


what kinds of string interpolation does POSIX sh support ?

By Gilles ‘SO-stop being evil’: source and license: [0]


"${blah}" and "$blah" are portable shell syntax: they work on all POSIX-compliant shells as well as in traditional Bourne shells. POSIX also requires other features of variable expansion:

In all cases, remember that the result of $… undergoes whitespace-splitting (more precisely, splitting at $IFS characters) and wildcard expansion (globbing) unless it’s in double quotes (or a few other contexts that don’t allow multiple words).

You can look up what exists in POSIX by reading the specification. Modern versions of POSIX are identical to the Open Group Base Specifications (without optional components). Older versions are a subset of Single Unix v2.

Unix-like systems without a POSIX shell are extremely rare nowadays. /bin/sh is a non-POSIX Bourne shell on a few systems, notably Solaris, but a POSIX shell is available (/usr/xpg4/bin/sh on Solaris, and you should have /usr/xpg4/bin ahead of /usr/bin in your PATH). If you need compatibility with Bourne shells, check the man page on the systems you’re interested in, as there have been many versions of sh with slightly different sets of features. Sven Mascheck maintains a page with a lot of information.