53 gnu history posix arguments
我不认为历史Unix 中的 shell/实用程序或像4.4BSD那样“最近”的东西支持使用双破折号(或两个连续的连字符)作为选项分隔符的结尾。使用FreeBSD,您可以看到例如在2.2.1 版本(1997)的rm
联机帮助页中引入的注释。但这只是一个命令的文档。
查看我能找到的最古老的GNU fileutils 更改日志,我看到了这个1(略有改动):
Tue Aug 28 18:05:24 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
* touch.c (main): Don't interpret first non-option arg as a <---
time if `--' is given (POSIX-required kludge).
* touch.c: Add long-named options.
* Many files: Include <getopt.h> instead of "getopt.h" since
getopt.h will be in the GNU /usr/include.
* install.c: Declare some functions.
* touch.c, getdate.y, posixtime.y, mktime.c: New files, from bin-src.
* posixtime.y: Move year from before time to after it (but
before the seconds), for 1003.2 draft 10.
Run Code Online (Sandbox Code Playgroud)
这早于Linux。很明显,您可能想要创建一个名称包含与时间规范相同位数(八位或十位十进制数)的名称的文件 - 而不是为现有文件指定时间戳...
--
) 作为选项分隔符的结尾吗?touch
90 年代初的文件名中使用数字,然后这以一种零碎的方式一次一个实用程序持续了十年??1. 与此相反,即在全局记录所有命令使用中的长选项,这是无关的。在另一方面,你可以看到参考定界符出现在像GNU rm.c于2000年作为一个评论,之前被暴露给最终用户在2005年(该diagnose_leading_hyphen功能)。但这一切都晚了,而且是关于一个非常具体的用例。
wwo*_*ods 39
据我所知,使用--
的结束选项-标记开始用sh
和getopt
在系统III UNIX(1980)。
根据Bourne Shell 家族的这段历史,Bourne Shell首次出现在Version 7 Unix (1979) 中。但它没有一种方式set
,以从分隔参数选项。所以原始的 Bourne shell 可以:
set -e
- 开启错误退出模式set arg1 arg2 ...
-设置位置参数$1=arg1
,$2=arg2
等等。但是:set arg1 -e arg2
会给你$1=arg1
, $2=arg2
,并打开 exit-on-error。哎呀。
System III Unix (1980) 修复了该错误并引入了getopt
. 根据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.
Run Code Online (Sandbox Code Playgroud)
据我所知,这是它出现的第一个地方。
从那里,似乎其他命令采用的--
约定来解析参数解析歧义(如用例touch
和rm
整个野生你上面举),20世纪80年代的无标天。
其中一些零碎的采用被编入POSIX.1 (1988),这是关于“POSIX-required kludge”的变更日志评论的来源。
但是直到POSIX.2 (1992)才采用了实用程序语法指南,其中包含著名的指南 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.
Run Code Online (Sandbox Code Playgroud)
这就是它从“kludge”到普遍推荐的地方。