Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 -- ?

share|improve this question
    
This answer has some background on the syntax of the find command. –  Anthon Apr 25 at 10:20

2 Answers 2

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.

share|improve this answer
    
that's indeed interesting –  Kiwy Apr 25 at 11:04

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.

share|improve this answer
1  
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. –  mtmiller Apr 30 at 2:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.