8

I've read several question about double dash:

Single dashes - for single-character options, but double dashes -- for words?
What does -- (double-dash) mean? (also known as “bare double dash”)

However I remember about a teacher 4 years ago telling me that -- was the posix way of dealing with long switches like --help or --color=.
Today, I'm using a lot of command where this rule is not respected at all and the best example I can came up with is find where no long switches takes a double-dash even with the very annoying AIX find.

Was my teacher wrong? or does the rule changes since (which seems unlikely)?
And finally, is there any posix rules about the length of option and - or -- ?

Kiwy
  • 9,534

2 Answers2

13

I think POSIX doesn't define long options :

Guideline 3: Each option name should be a single alphanumeric character (the alnum
character classification) from the portable character set. The -W (capital-W) option shall be reserved for vendor options.

Multi-digit options should not be allowed.

The double dash is a GNU convention.

In the POSIX definition of find the "long switches" with single dash are not part of the options, but an expression given as an operand.

Leiaz
  • 4,462
  • 1
  • 25
  • 14
2

find seems to be the exception to the rule. Actually find originated outside of the group of initial utility developers for Unix, hence it non-conformant way of using 'long' options.

As so often, the standardization happened only after the use of short-options and long-options had become common practice in most programs, and that partly because some routines, or library became available for doing the option parsing (thereby enforcing some non-explicit standard). But of course at that time it was too late to change existing programs, like find, in a way that would not break scripts. POSIX compliance, with double dashes, is less important than not breaking these scripts.

Backwards compatibility is e.g. also the reason why short options for tar can be specified with or without a dash.

Anthon
  • 79,293
  • 3
    The kill and test command are two other exceptions. test has two-character arguments like -lt and -eq, although these are more like syntax that just happen to start with a dash. And ps is another one that supports options without dashes for legacy compatibility. – Michael Miller Apr 30 '14 at 02:39