-2

The following image is from the POSIX documentation's section on Utility Argument Syntax. Ellipses guideline My question is this: Are the two argument forms in the image more or less identical, besides one using the option -g and the second using -f as an option? The wording makes it sound like an ellipses following a pair of brackets means that the argument inside the brackets must occur at least once, rather than an arbitrary number of times. That is, is an argument of the form [-f option_argument]... equivalent to an argument of the form -f option_argument [-f option_argument]..., wherein both forms specify that one or more occurrences of the string must be present? Or, does the first form specify zero or more occurrences, and the second form specifies one or more occurrences?

1
  • @JeffSchaller, I would just put a period there, not a question mark.
    – ilkkachu
    Sep 21, 2021 at 20:15

1 Answer 1

4
  • -f arg [-f arg]... means -f arg must occur at least once, but that it may occur several times ("once and then zero or several times more" would be another way of saying it). The brackets designate optional parts of the command's command line semantics, and the ellipses say that option and its option-argument may be repeated any number of times.

    An example of this is found in one of the synopsis forms of the sed utility:

    sed [-n] -e script [-e script]... [-f script_file]... [file...]
    

    Here, -e script must occur once, but may occur more than once.

  • [-g arg]... means that -g arg may occur zero or several times, i.e that the -g option and its option-argument are optional.

    This is the case for the -f script_file option and option-argument in the example with sed above.

This is what the text in the image is trying to convey.

Without the ellipses, i.e. [-h arg], it would mean that -h arg is optional and that it would be accepted once on the command line. The utility may then decide what to do if a user uses -h arg multiple times (output a diagnostic message, let the later -h arg override earlier ones, or ignore further copies of the option, for example).

This is how -n works in the example with sed above. It is optional and using -n more than once does not have any special effect at all (it is ignored).

3
  • Thanks! I think I understand it now. I was mostly confused about why some expressions use ellipses outside of the brackets versus inside (e.g. [-f arg]... and [operand...]). Both expressions seem to indicate that the argument can occur 0 or more times. But, I think the former expression requires ellipses on the outside to capture the full expression, rather than just the last word. I.e. [-f arg...] would instead mean the whole string is optional, and if you exercise that option then the -f must occur exactly once, but the arg can occur 0 or more times. Is this the case? Sep 22, 2021 at 17:27
  • @NicholasCousar As options usually take either zero or one option-argument, using [-f arg...] doesn't make much sense.
    – Kusalananda
    Sep 22, 2021 at 17:32
  • right. It would not make much sense semantically. I am just trying to understand the syntax. Also, I was wrong earlier when I said the arg in [-f arg...] can occur 0 or more times. Within the context of the option [-f arg...], arg... says that arg must occur at least once and then can be repeated 0 or more times. Sep 22, 2021 at 17:48

Not the answer you're looking for? Browse other questions tagged .