Any POSIX lawyers around?
Various printf(1) implementations attempt option parsing on the first argument and choke on something like "printf ---":
FreeBSD sh(1) builtin: printf: Illegal option --
FreeBSD standalone: printf: illegal option -- -
bash(1) builtin: -bash: printf: --: invalid option
POSIX does not specify any options for printf(1).
The workaround is to explicitly terminate option parsing with "--",
i.e., "printf -- ---". That works at least across OpenBSD, FreeBSD,
GNU coreutils and bash. But does it conform to POSIX?
Various printf(1) implementations attempt option parsing on the first argument and choke on something like "printf ---":
FreeBSD sh(1) builtin: printf: Illegal option --
FreeBSD standalone: printf: illegal option -- -
bash(1) builtin: -bash: printf: --: invalid option
The workaround is to explicitly terminate option parsing with "--",
i.e., "printf -- ---". That works at least across OpenBSD, FreeBSD,
GNU coreutils and bash. But does it conform to POSIX?
On 2026-11-17, Christian Weisgerber <naddy@mips.inka.de> wrote:
Various printf(1) implementations attempt option parsing on the first
argument and choke on something like "printf ---":
FreeBSD sh(1) builtin: printf: Illegal option --
FreeBSD standalone: printf: illegal option -- -
bash(1) builtin: -bash: printf: --: invalid option
POSIX does not specify any options for printf(1).
However, POSIX does still specify the -- option for printf; it's just
not spelled out in the description of printf.
Contrast this situation with that of the echo utility. For echo,
much more is written than just "OPTIONS ... None":
The echo utility shall not recognize the "--" argument in the manner
specified by Guideline 10 of XBD 12.2 Utility Syntax Guidelines; "--"
shall be recognized as a string operand.
Implementations shall not support any options.
The printf utility is in no way similarly excused from supporting --,
nor forbidden from having options courtesy of the implementor.
(Implementations of echo, such as the Bash builtin and the coreutils
echo, ignore the proscription against supporting options.)
Although coreutils printf accepts long options when you don't have
POSIXLY_CORRECT set:
bash$ echo --version
--version
bash$ POSIXLY_CORRECT=1 /bin/echo --version
--version
bash$ /bin/echo --version
echo (GNU coreutils) 9.1
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 5 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 498677:43:19 |
| Calls: | 212 |
| Calls today: | 3 |
| Files: | 912 |
| D/L today: |
31 files (22,593K bytes) |
| Messages: | 69,841 |