Somewhere I saw a rant against java/javac allegedly using a mix of Windows and Unix style like
java -classpath ... -ea ... Something
IMHO, it is no mix, it's just like find
works as well, isn't it? AFAIK, according to POSIX, the syntax should be like
java --classpath ... --ea ... Something
and -abcdef
would mean specifying 6 short options at once. I wonder which version leads in general to less typing and less errors.
I'm writing a small utility in Java and in no case I'm going to use Windows style /a /b
since I'm interested primarily in Unix. What style should I choose?
Best Answer
You can find the POSIX argument conventions in the Utility Conventions chapter. The POSIX style consists of options with a single dash followed by a single letter indicating the option, with the argument value separated from the option by a space.
There are exceptions to the rules -
find
, for example - but these are because of the historical Unix precedents.The X Windows (X11) uses
find
-like single-dash, long name options.The double-dash long name options were pioneered by GNU (after a detour using
+
as a prefix).See this StackOverflow question for a discussion of the wide variety of known command line argument handling systems - there are lots. (Since this was written, the powers-that-be decided the question SO 367309 was not a good fit for SO. I've transferred the answer to another question, What is the general syntax of a Unix shell command?.)
You could extend the list of techniques to cover
git
(and a number of other systems) where you get a structure like:basecommand
[global options]subcommand
[sub-command options] [name ...]There may be many sub-commands, each with its own lexicon of options.
Of course, Windows uses (used) slash '
/
' to indicate options instead of dash '-
'.JCL (for z/OS, and OS/360, and intermediate systems) tends to use positional parameters separated by commas, and is generally regarded as not being user-friendly or a good interface.