1

eg.

git diff [options] [<commit>] [--] [<path>...]

What's the reason -- is used here? Is it to separate groups of positional parameters, namely commit and path's? Would this explanation be consistent with other commands' usage of --?

imagineerThat
  • 5,293
  • 7
  • 42
  • 78
  • 1
    It signifies **end of options**. What remains will be arguments, like `path`. Try `printf "--\n"` without first giving `printf -- "--\n"` – David C. Rankin Dec 10 '17 at 19:22
  • As options are normally given as a hyphen followed by a letter, or maybe a digit, a double hyphen is nice for saying "option: no option" - or "option: no more options". I find it nice. – linuxfan says Reinstate Monica Dec 10 '17 at 19:37

1 Answers1

3

The generalized use of this sigil is specified in POSIX Utility Syntax Guidelines:

Guideline 10: The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.

Thus, paths that begin with - can be specified without the need for a prefix such as ./ if -- is specified as a prior option in a tool compliant with the above guidelines.

While tools (such as git) that are not specified by POSIX are not required to comply with the standard, doing so remains good form.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441