Daniel Dickman <[email protected]> writes:

> On Wed, Mar 9, 2016 at 9:35 PM, Michael McConville <[email protected]> wrote:
>> Jeremie Courreges-Anglas wrote:
>>> >> @@ -66,13 +66,18 @@ main(int argc, char *argv[])
>>> >>            argv++;
>>> >>    }
>>> >>
>>> >> -  while ((ch = getopt(argc, argv, "n:")) != -1) {
>>> >> +  while ((ch = getopt(argc, argv, "c:n:")) != -1) {
>>> >>            switch (ch) {
>>> >> +          case 'c':
>>> >> +                  dobytes = 1;
>>> >> +                  p = optarg;
>>> >> +                  break;
>>> >>            case 'n':
>>> >> +                  dobytes = 0;
>>> >
>>> > It's already initialized to 0, which is necessary for the head -count
>>> > style syntax.
>>>
>>> I followed the behavior of GNU head here: the last specified option
>>> wins.  IIRC FreeBSD head(1) makes -c and -n incompatible.
>>
>> I feel like erroring on multiple options would be an improvement. I
>> guess I can propose that as a separate diff when you're done.
>>
>
> I don't think erroring would be expected behaviour.

Same here.

> I think jca@ has the right approach (especially if it matches what
> FreeBSD and others do in this case).

The situation is a bit muddy. :)
1. GNU head obeys the last command line option
2. FreeBSD errors out if both -c and -n are specified
3. NetBSD always follows -c if it has been specified, probably mixing -c
   and -n was overlooked
4. busybox is a bit more broken:

  $ printf '%s\n' a b c d e | busybox head -c 2 -n 5
  a
  b
  c$

  ie if -c is passed it always specifies the byte-counting behavior, but
  the actual byte count can be modified by subsequent -n options...

I prefer 1. 'cause I see no reason to do 2.

> Some posix tools say what they do
> in this case with text like this:
> "...the last option specified in each set shall determine the output."
>
> The equivalent in our man pages is text like:
>
> "It is not an error to specify more than one of the following mutually
> exclusive options..."
>
> "Where more than one option is specified from the same mutually
> exclusive group, the last option given overrides the others"
>
> (e.g. man df, man ls, etc).

*nod*

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to