0

Every instance I've found of printf(1) (that is, the command-line version; as opposed to printf(3), the C library) repeats its format-string to consume more when presented with too many arguments, allowing for constructions such as

printf '%s\n' "${headers[@]}" "" "${body}" > http_client_socket

However, is this platform-specific? If so, which platforms does it differ from this on?

Additionally (and regardless of the answer to the previous question), is it in the spec, or is it an undefined behavior?

JamesTheAwesomeDude
  • 845
  • 3
  • 14
  • 31
  • It's in the POSIX spec, see quote and link in the accepted answer ^there – muru May 09 '21 at 02:10
  • @muru Aha, nice! So it is POSIX-specified. (I'm still a bit curious if any major implementations buck this, but this answers the core of my curiosity.) – JamesTheAwesomeDude May 09 '21 at 02:14
  • 1
    You could edit the question to focus only on that and have it reopened. I can't say for sure, but the manpages of most of the older systems in https://www.freebsd.org/cgi/man.cgi have some variant of the phrase "The format string is reused as often as necessary to satisfy the arguments" (where printf is provided by the system in the first place). The exception was HP UX, which still says it conforms to the POSIX spec, so I assume the manpage simply didn't mention this detail. – muru May 09 '21 at 02:29

0 Answers0