Shell – Where is the `–` (double dash) argument documented

documentationoptionsshell

There are some utilities that accept a -- (double dash) as the signal for "end of options", required when a file name starts with a dash:

$ echo "Hello World!" >-file

$ cat -- -file
Hello World!

$ cat -file                      # cat - -file fails in the same way.
cat: invalid option -- 'f'
Try 'cat --help' for more information.

But some of those utilities don't show such an option in the manual page.

The man page for cat doesn't document the use (or validity) of a -- argument in any of the OS'es. This is not meant to be a Unix – Linux flame war, it is a valid, and, I believe, useful concern.

Neither cat, mv, ed (and I am sure many others) document such an option in their manual page that I can find.

Note that ./-file is a more portable workaround to the use of --.
For example, the source (dot) command (and written as .) doesn't (generally) work well with an -- argument:

$ echo 'echo "Hello World!"' >-file

$ . ./-file
Hello World!

$ . -file
ksh: .: -f: unknown option
ksh: .: -i: unknown option
ksh: .: -l: unknown option
ksh: .: -e: unknown option
Usage: . [ options ] name [arg ...]

$ . -- -file         # works in bash. Not in dash, ksh, zsh.
ksh: .: -file: cannot open [No such file or directory]

Best Answer

This is a POSIX requirement for all utilities, see POSIX chapter 12.02, Guideline 10 for more information:

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.

POSIX recommends all utilities to follow these guidelines.

There are a few exceptions like echo (read at OPTIONS). And special builtins that do not follow the guidelines (like break, dot, exec, etc.) :

Some of the special built-ins are described as conforming to XBD Utility Syntax Guidelines. For those that are not, the requirement in Utility Description Defaults that "--" be recognized as a first argument to be discarded does not apply and a conforming application shall not use that argument.

The intent is to document all commands that do not follow the guidelines in their POSIX man page, from POSIX chapter 12.02 third paragraph:

Some of the standard utilities do not conform to all of these guidelines; in those cases, the OPTIONS sections describe the deviations.

As the cat POSIX man page documents no deviations in the OPTIONS section, it is expected that it accept -- as a valid argument.

There still may be (faulty) implementations that fail to follow the guideline.

In particular, most GNU core utilities follow this guideline

Related Question