On Sun, Oct 10, 2021 at 08:26:04PM -0400, gwes wrote: > On 10/10/21 5:03 PM, Scott Cheloha wrote: > > [...] > > > > If we want to have the unportable legacy syntax then it should work > > like other option arguments. Option arguments can be respecified > > multiple times in most other utilities. The last such appearance of > > an option argument is the one the utility uses. That's how option > > arguments work, for the most part. > > > > We could remove the legacy syntax and shave a couple lines of code. > > > > OTOH, supporting it fully is super easy. I've provided a patch. > > > The man page says head [-count | -n count] [file ...] > There are only two valid switches. > One, the other, or none. > Using more than one is -undefined-. > I doubt it ever has been defined. > It could be asserted that any more than 1 switch is an error.
No. It wouldn't be an error, it would be undefined. Just like you said. UB is not an argument for preserving the current behavior. If anything, UB suggests we should do the least surprising thing. Lucky for us, the least surprising thing is easy to pinpoint because we have decades of prior art to use as a guide. Let's look at the timeline: - head(1) first appears in 1BSD. It accepted multiple -count arguments and only used the last one found, if any: https://github.com/dspinellis/unix-history-repo/blob/BSD-1/s6/head.c#L26 - BSD head(1) then kept this behavior in all releases up through 4.3BSD: https://github.com/dspinellis/unix-history-repo/blob/BSD-4_3/usr/src/ucb/head.c#L39 - 4.3-Tahoe and 4.3-Reno then lost the behavior: https://github.com/dspinellis/unix-history-repo/blob/BSD-4_3_Tahoe/usr/src/ucb/head.c#L43 https://github.com/dspinellis/unix-history-repo/blob/BSD-4_3_Reno/usr/src/usr.bin/head/head.c#L45 - Acceptance of multiple -count arguments then reappears in 1992 during the development of 4.4BSD: https://svnweb.freebsd.org/csrg/usr.bin/head/head.c?revision=52824&view=markup#l97 - The behavior is then present in all 4.4 releases (Lite1, Lite2, and 4.4): https://github.com/dspinellis/unix-history-repo/blob/BSD-4_4_Lite1/usr/src/usr.bin/head/head.c#L126 https://github.com/dspinellis/unix-history-repo/blob/BSD-4_4_Lite2/usr/src/usr.bin/head/head.c#L128 https://github.com/dspinellis/unix-history-repo/blob/BSD-4_4/usr/src/usr.bin/head/head.c#L126 - FreeBSD picked up the behavior from one of the 4.4-Lite trees in 1994: https://cgit.freebsd.org/src/commit/usr.bin/head/head.c?id=9b50d9027575220cb6dd09b3e62f03f511e908b8 - It is present in FreeBSD's head(1) to this day: https://cgit.freebsd.org/src/tree/usr.bin/head/head.c#n192 - NetBSD picked up the behavior from 4.4-Lite2 in 1997: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/head/head.c?rev=1.7&content-type=text/x-cvsweb-markup&only_with_tag=MAIN - It is present in NetBSD's head(1) to this day: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/head/head.c?rev=1.24&content-type=text/x-cvsweb-markup&only_with_tag=MAIN - DragonflyBSD got their head(1) implementation from FreeBSD in 2003. They have always had the behavior, and have it to this day: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/usr.bin/head/head.c#L160 - OpenSolaris head(1) supported multiple -count arguments at release in 2005: https://github.com/illumos/illumos-gate/blob/7c478bd95313f5f23a4c958a745db2134aa03244/usr/src/cmd/head/head.c#L76 - I don't have the source code but I'd imagine the support for multiple -count arguments was present in many older Solaris releases before OpenSolaris appeared. - illumos (and presumably Solaris) head(1) retains the behavior to this day: https://github.com/illumos/illumos-gate/blob/a9e414682948591ec63d5ab2cd11ba55603b59fa/usr/src/cmd/head/head.c#L83 > If you have an old man page that says {[ -count | -n count ] ...} > then your argument has some merit. The documentation is not an ironclad guarantee of behavior. Only the source code can have behavior. I have demonstrated a particular behavior in the BSD head(1) source code across decades of releases. -- In summary: Theo forked NetBSD in 1995, before they imported the -Lite2 changes for head(1). The fact that OpenBSD's head(1) does not support multiple -count arguments is an accident of timing, not conscious choice.