0

Why do scripts in Linux use - and -- as parameter prefixes?

What I mean is why do they use - (for example $ git --help) instead of something like >, (so it would be $ git >>help) or even something like $ git-help? I know it probably doesn't make a difference what scripts use as a parameter prefix, but why did they choose - in particular?

  • Long established tradition. Also, things like > have other meanings in the shell (output redirection in this case): reusing it as an option flag would be ... difficult. – NickD May 31 '18 at 21:07
  • Scripts cannot change the expectations of the programs they run. If git expects its options to begin with double dashes then they must begin with double dashes. Note that different programs have different expectations; see for example, dd and tar. – AlexP May 31 '18 at 21:11
  • 1
    Why not? There are three fundamental lineages: UNIX and now Linux use mostly dashes and double dashes (ls -l); VMS, CP/M, MS-DOS and Windows use mostly forward slashes (dir /w); and the ancient and honorable IBM JCL uses keyword=value (DD IF=...). But note than even on Windows there are plenty programs which want dashes (e.g., ping -i 2 -n 3); on Linux dd mimics the IBM JCL tradition, and tar is eccentric (tar xvzf ...). – AlexP May 31 '18 at 21:14
  • @AlexP amusingly enough, some versions of DOS supported - to introduce options (configurable in a subset of those versions using SWITCHAR). – Stephen Kitt May 31 '18 at 21:50

1 Answers1

1

In the 1960s, Multics introduced '-' as the prefix for options (short and long options).

Early UNIX versions in the early 1970s only used short options.

In the late 1970s, UNIX partially introduced long options, using the Multics method.

In 1980, a few former AT&T employees created Charles River Data Systems and the UNIX clone UNOS that massively used long options in the Multics style.

Around 1988, GNU introduced '--' as long option prefix and since Linux is dominated by GNU software, there is a lot of software on Linux that uses '--', even though it is non-standard.

schily
  • 19,173
  • "there is a lot of software on Linux that uses '--', even though it is non-standard" -- How is a single dash any more "standard" than a double dash? – phemmer Jun 01 '18 at 00:30
  • If you check the POSIX rules for options, you will see that you need to disregard one rule more than with single dash long options, if you like to implement double dash long options. – schily Jun 01 '18 at 01:42
  • Where are you getting that from? POSIX makes allowances specifically so double dashes are supported. Plus it only cares about the argument syntax of commands specifically referenced within the documentation. – phemmer Jun 01 '18 at 03:56
  • I don't think the standard has rules for nonstandard utilities (how would that even work?). There are Utility Conventions with a description of the syntax of standard utilities and general guidelines. Guidelines aren't really rules. – ilkkachu Jun 01 '18 at 07:59
  • See POSIX section 12.2. Single dash long options disregard guideline 3 once, double dash options disregard it twice. Note that single dash long options are in use (without problems) since more than 50 years, while double dash long options have been introduced 30 years ago using a reason that has been verified to be void since 20+ years at that time. I am massively using single dash long options since 36 years and dislike the double dash variant. I however tolerate in my getargs() based on the UNOS concept when people specify a second dash with long options. GNU getopt_long() should do that too – schily Jun 01 '18 at 08:25