Até onde eu sei, o uso de -- como marcador de fim de opções começa com sh e getopt no System III Unix (1980).
De acordo com essa história da família Bourne Shell , o Bourne Shell primeiro apareceu em Versão 7 Unix (1979). Mas não tinha como set separar as opções dos argumentos . Então, o shell Bourne original poderia fazer:
-
set -e- ativar o modo de sair no erro -
set arg1 arg2 ...- define os parâmetros posicionais$1=arg1,$2=arg2, etc.
Mas: set arg1 -e arg2 daria a você $1=arg1 , $2=arg2 e ativar a saída-em-erro . Ops.
System III Unix (1980) corrigiu esse bug e introduziu getopt . De acordo com a página de manual do getopt :
NAME
getopt - parse command options
SYNOPSIS
set -- 'getopt optstring $∗'
DESCRIPTION
Getopt is used to break up options in command lines for easy parsing by
shell procedures, and to check for legal options. Optstring is a
string of recognized option letters (see getopt(3C)); if a letter is
followed by a colon, the option is expected to have an argument which
may or may not be separated from it by white space. The special option
-- is used to delimit the end of the options. Getopt will place -- in
the arguments at the end of the options, or recognize it if used
explicitly. The shell arguments ($1 $2 . . .) are reset so that each
option is preceded by a - and in its own shell argument; each option
argument is also in its own shell argument.
Tanto quanto eu posso dizer, esse é o lugar primeiro que aparece.
A partir daí, parece que outros comandos adotaram a convenção -- para resolver ambigüidades de análise de argumentos (como os exemplos com touch e rm que você cita acima) durante os dias normais e sem padrão da década de 1980. / p>
Algumas dessas adoções parciais foram codificadas em POSIX.1 (1988), que é onde o comentário do changelog sobre o "POSIX-required kludge" vem.
Mas não foi até POSIX.2 (1992) que as Diretrizes de Sintaxe do Utilitário foram adotadas, que contêm a famosa Diretriz 10:
Guideline 10: The 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. The "--" argument
should not be used as an option or as an operand.
E é aí que passa de ser um "kludge" para uma recomendação universal.