No, it's not.  Per POSIX XCU 1.4, utilities that do not explicitly
state otherwise are allowed to recognize options whether any are
defined by the standard.  printf(1) follows that default, so for the
first positional argument to (portably) start with a minus-sign, a --
option must precede it, ala
  printf -- -s

Or, you know, don't get into a habit that created a million printf(2)
vulnerabilities and write
  printf %s -s

instead.

Philip Guenther


On Fri, Mar 14, 2025 at 11:31 PM Christian Schulte <c...@schulte.it> wrote:
>
> Hi @misc,
>
> I recently stumbled upon an issue with GNU printf(1). I was using
> echo(1) in a testsuite.at on OpenBSD successfully, but that failed on
> linux badly. The OpenBSD man page of echo(1) contains this sentence:
>
> Where portability is paramount, use printf(1).
>
> So I replaced echo(1) with printf(1). This leads to...
>
> OpenBSD:
>
> x500$ printf -0
> -0x500$ printf -something
> -somethingx500$
>
> which is the expected output. On linux I get
>
> schulte@vps:~$ printf -0
> -bash: printf: -0: invalid option
> printf: usage: printf [-v var] format [arguments]
> schulte@vps:~$ printf -something
> -bash: printf: -s: invalid option
> printf: usage: printf [-v var] format [arguments]
>
> Would you rate this a bug in GNU printf(1)?
>
> --
> Christian
>

Reply via email to