Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conventions for command line verb arguments -a vs --arg

I've just noticed a pattern (in git and the CommandLineParser lib for .NET) for verb-style command arguments, and wondering if someone can confirm:

myprog dothis -a "someArg"

  • -a
  • --arg

What's the difference between the single-dash-prefix and the double-dash-prefix? Is the single dash prefix always for a single-letter argument specifier, where a double dash prefix always for a "long name" of the argument?

Is there a formal convention somewhere that drives this, or is it a generally accepted informal practice? (or am I just making something of nothing?)

Just curious... the I had never noticed the pattern in git and the CommandLineParser docs are pretty thin and some blog post or another implicated the convention.

(for that matter... what's this style of verb/args even called? I can't seem to find much of anything on it)

like image 448
jleach Avatar asked Feb 12 '17 03:02

jleach


1 Answers

From the wikipedia: https://en.wikipedia.org/wiki/Command-line_interface

Option conventions in Unix-like systems

In Unix-like systems, the ASCII hyphen-minus begins options; the new (and GNU) convention is to use two hyphens then a word (e.g. --create) to identify the option's use while the old convention (and still available as an option for frequently-used options) is to use one hyphen then one letter (e.g. -c); if one hyphen is followed by two or more letters it may mean two options are being specified, or it may mean the second and subsequent letters are a parameter (such as filename or date) for the first option.

Two hyphen-minus characters without following letters (--) may indicate that the remaining arguments should not be treated as options, which is useful for example if a file name itself begins with a hyphen, or if further arguments are meant for an inner command (e.g. sudo). Double hyphen-minuses are also sometimes used to prefix "long options" where more descriptive option names are used. This is a common feature of GNU software. The getopt function and program, and the getopts command are usually used for parsing command-line options.

like image 141
David Ranieri Avatar answered Oct 31 '22 17:10

David Ranieri