15.3.15 Shell Format Strings

There are two kinds of format strings in shell scripts: those with dollar notation for placeholders, called Shell format strings and labelled as ‘sh-format’, and those acceptable to the ‘printf’ command (or shell built-in command), called Shell printf format strings and labelled as ‘sh-printf-format’.

Shell format strings, as supported by GNU gettext and the ‘envsubst’ program, are strings with references to shell variables in the form $variable or ${variable}. References of the form ${variable-default}, ${variable:-default}, ${variable=default}, ${variable:=default}, ${variable+replacement}, ${variable:+replacement}, ${variable?ignored}, ${variable:?ignored}, that would be valid inside shell scripts, are not supported. The variable names must consist solely of alphanumeric or underscore ASCII characters, not start with a digit and be nonempty; otherwise such a variable reference is ignored.

Shell printf format strings are the format strings supported by the POSIX ‘printf’ command (https://pubs.opengroup.org/onlinepubs/9799919799/utilities/printf.html), including the floating-point conversion specifiers a, A, e, E, f, F, g, G, but without the obsolescent b conversion specifier. Extensions by the GNU coreutils ‘printf’ command (https://www.gnu.org/software/coreutils/manual/html_node/printf-invocation.html) are not supported: use of the ‘'’ flag in the %i, %d, %u, %f, %F, %g, %G directives; use of ‘*’ or ‘*m$’ as width or precision; use of size specifiers h, l, j, z, t (ignored); and the escape sequences \c, \xnn, \unnnn, \Unnnnnnnn. Extensions by the GNU bash ‘printf’ built-in (https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-printf) are not supported either: use of ‘*’ as width or precision; use of size specifiers h, l, j, z, t (ignored); the %b, %q, %Q, %T, %n directives; and the escape sequences \xnn, \unnnn, \Unnnnnnnn.