-1

I am trying to parse options for my script with getopts and I decided that it would be best to read up on it in the POSIX standard, as it's usually extremely helpful. The DESCRIPTION section is fairly ambiguous in regard to the use of colon (:) in optstring, so I looked up how people use : with getopts on the internet and now I'm confused. What does colon do in commands like getopts abc:d name and how am I supposed to know just by reading the standard?

2
  • 1
    Look further down, in Operands: "If a character is followed by a <colon>, the option shall be expected to have an argument, which should be supplied as a separate argument."
    – muru
    Aug 22, 2023 at 16:10
  • which part of the description is ambiguous, exactly?
    – ilkkachu
    Aug 22, 2023 at 18:26

1 Answer 1

4

A colon following an option letter indicates that the option takes an argument; this is described in the “operands” section:

If a character is followed by a <colon>, the option shall be expected to have an argument, which should be supplied as a separate argument.

So abc:d means that the valid options are -a, -b, -d with no argument, and -c followed by an argument.

2
  • Thank you! That's exactly what I needed. Aug 22, 2023 at 17:26
  • 1
    @NicolasDumitru Good! If this solves your issue, please consider accepting the answer. Accepting an answer marks the issue as resolved.
    – Kusalananda
    Aug 22, 2023 at 17:42

You must log in to answer this question.

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