Replies: 5 comments 17 replies
-
The answer to the above is simple: yes. The case in the title is not portable and fails under POSIX rules. The reason is that many implementations support options as an extension, and POSIX allows for this by requiring an option parsing pass whether or not there actually are options. The
This is clearly incorrect. The Utility Syntax Guidelines apply to all the utilities, except where explicitly specified otherwise. Or, as POSIX puts it, in 12.2: “The utilities in the Shell and Utilities volume of POSIX.1-2017 that claim conformance to these guidelines shall conform completely to these guidelines as if these guidelines contained the term "shall" instead of "should". On some implementations, the utilities accept usage in violation of these guidelines for backwards-compatibility as well as accepting the required form.” Which brings me to a compile-time option I recently added to ksh and which is now in 93u+m/1.0.9, I think that approach is much better than the one the illumos people took in their fork of ksh, which is to break things like |
Beta Was this translation helpful? Give feedback.
-
They said that the "Utility Syntax Guidelines" page claims that all utilities should follow them unless otherwise specified. "The xyz utility shall conform to XBD Utility Syntax Guidelines." When I had the time to finally read what text they were referring to, I even commented that the text:
I commented that I think that obviously does not say that "All utilities conform to guidelines unless specified otherwise", but that "Not all utilities that conform to guidelines conform to all of them exactly, in which case the difference is specified"; for example, Utilities without the explicit "shall conform to XBD Utility Syntax Guidelines." note need not conform to them; all utilities without POSIX options will not have that note.
o/ |
Beta Was this translation helpful? Give feedback.
-
Thanks. Much appreciated.
Indeed. I also reached a similar conclusion before I posted but didn't want to make the post even bigger. Base definitions, Conformance, 2.1.1.4:
So to support additional options by an implementation (while staying conformant), utilities, even without options, must accept This is somewhat off topic, but I think this poses an issue for the standard. Because, as demonstrated earlier, this does not seem a unanimous interpretation. E.g. open/free bsd reject I think it would be good if this:
Also had a clarification, maybe like
Are there existing discussions of this subject? Specifically that standard utilities without options are required to support I did try to search the Austin group bug tracker, but I didn't find anything related that I could identify. |
Beta Was this translation helpful? Give feedback.
-
@McDutchie thanks for posting the question at the open group. I wanted to post it at the bug tracker but discovered my account did not automatically extend to the tracker... so I asked here. To quote from XCU 1.4 ("Shells and Utilities", "Introduction") as replied:
So I think this settles it. But I still think a clarification would be useful at XBD 12.2, or at least a reference to XCU 1.4, because clearly not all implementation follow it, despite it being very easy to implement. |
Beta Was this translation helpful? Give feedback.
-
For future reference, this (my) interpretation is invalid. It simply states: "if there are exceptions to the guidelines, they'll be listed at the OPTIONS section". And it doesn't say anything about utils which don't list exceptions, such as "OPTIONS: None.", so it was not possible to deduce that "OPTIONS: None" requires to follow the guidelines. The other arguments that without supporting "--" it would become non-portable and non-extensible are indeed valid, but only XCU 1.4 default OPTIONS states it explicitly, and was indeed the missing link. |
Beta Was this translation helpful? Give feedback.
-
This is more of a question to the Austin group, but it does apply to ksh93[u+m] as well, and I am hoping the experienced people here would be able to help.
The question at the title is an example case to demonstrate an issue, and the more general question is:
Is the form
printf -- "$format" ...
portable, in the sense than a conformant implementation is required to support it?And even more generically:
Is a utility in the "Shell and Utilities" section required to accept
--
as "end of options" (unless explicitly stated otherwise) even when the utility has no options (likeprintf
), i.e. that the options section of that utility spec looks like:So far, as far as I can tell and interpret the spec, the answer is that utilities should accept
--
as "end of options" even when the utility has no options (unless stated otherwise).From Base-definitions, "12.2 Utility Syntax Guidelines" (which include the specification for
--
):Which I interpret as "The standard utilities shall conform to these guidelines, unless stated otherwise at the OPTIONS section".
And indeed, for some utilities (
echo
,test
,:
) it's stated explicitly, e.g. fortest
:The counter argument which was raised at the #ksh irc channel on libera - on whether
printf
is required to support--
is, and I'm quoting:Which likely draws from the fact that the docs for utilities which do accept options typically (always?) state that it shall conform with the syntax guidelines, for instance for
date
:Some data points, without claiming it proves anything:
printf
which I tested, all of them accept--
as "end of options". Most of the variants are builtin implementations of shells (bash, ksh93[u+m], zsh (eh...), dash, free/net bsd sh, busybox ash, Schily posix Bourne sh variants, yash, and few more) with and without posix compatibility options where available, but also system/usr/bin/printf
on linux, illumos, and even 1981 BSD 2.11 on PDP11. Bare none, all support--
as "end of options".printf
is not required to accept--
as "end of options", then I think it must print-vx
forprintf -v%s x
, at which case, of the 24 printf variations which I tested, only 4 are conformant with this specific input and indeed print-vx
(netbsd sh, busybox ash, zsh, and gnu/bin/printf
). All the others (including BSD 2.11) error on invalid option.basename -- foo/bar
printsbar
on most systems, but on illumos it prints--
. orecho | dd -- bs=1
works on linux and illumos, but on freebsd and openbsd it printsdd: unknown operand --
.So, are standard utilities which have "OPTIONS: None." required to support
--
as "end of options"? or not?Should printf?
(for
printf
specifically there's a general solution which doesn't work with other utilities: replace a leading-
at the format with\055
which is its equivalent octal literal in ASCII, and don't use--
. but preferablyprintf -- "$fmt"...
is portable...)Beta Was this translation helpful? Give feedback.
All reactions