简体   繁体   English

“--”和“-”在任何 Unix Shell 上是什么意思?

[英]What does "--" and "-" mean on any Unix Shell?

can someone tell me whats the difference between - and -- .谁能告诉我---之间有什么区别。 For example, in this command:例如,在这个命令中:

 docker run --name some-name -e MYSQL_ROOT_PASSWORD=some_password mysql

I understand that I am running a docker container with mysql as image, with the name some-name and the password some_password.我知道我正在运行一个以 mysql 作为映像的 docker 容器,名称为 some-name,密码为 some_password。 What I do not get is why I use -- for the name parameter and - for the password parameter.我不明白的是为什么我使用--作为名称参数和-作为密码参数。

这是一个任意约定,并非所有程序都遵循它,但通常 - 在单字母参数之前,并且 - 在全字或多字参数之前。

By POSIX standard , options are letters preceded by a single dash.根据POSIX 标准,选项是以单个破折号开头的字母。 They can be combined;它们可以组合在一起; eg ls -l -a is equivalent to ls -la .例如ls -l -a等价于ls -la

By GNU convention , long options are preceded by two dashes.根据GNU 约定,长选项前面有两个破折号。 Obviously, you can't combine them like normal options, but they are more readable.显然,您不能像普通选项一样组合它们,但它们更具可读性。

Most options will have both forms;大多数选项都有两种形式; for example, most programs recognise -h and --help as equivalents.例如,大多数程序将-h--help视为等价物。

What does “--” and “-” mean on any Unix Shell? “--”和“-”在任何 Unix Shell 上是什么意思?

-- and - have no meaning in the shell. ---在 shell 中没有意义。

These are simply parameters for the docker command.这些只是docker命令的参数。

If you want to know what meaning they have for the docker command, you will have to look them up in man docker .如果你想知道它们对docker命令的意义,你必须在man docker查找它们。

There is absolutely no difference between --name , -e , foo , or --!--!--!-- . --name-efoo--!--!--!--之间绝对没有区别。 They are all simply parameter names, the - is simply as much part of the name as the n or the e .它们都只是参数名称, -ne一样只是名称的一部分。

--name is the name of a parameter, -e is the name of a parameter, run is the name of a parameter. --name是参数名, -e是参数名, run是参数名。

What I do not get is why I use -- for the name parameter and - for the password parameter.我不明白的是为什么我使用--作为名称参数和-作为密码参数。

The short answer is: because that's what the author of the docker command chose to call those parameters.简短的回答是:因为这是docker命令的作者选择调用这些参数的方式。

The slightly longer answer is that there are some conventions that some commands follow to some degree.稍微长一点的答案是有些命令在某种程度上遵循了一些约定。 On particular, docker seems to follow these three very common conventions:特别是, docker似乎遵循以下三个非常常见的约定:

  • " subcommand ": this is a convention that was popularized by tools like iproute2 and git , which have a single "master" command whose first parameter is the name of a "subcommand" (which then can have even more subcommands), for example: ip route , ip addr add , git commit , git status , docker run . subcommand ”:这是一个由iproute2git等工具推广的约定,它们有一个“主”命令,其第一个参数是“子命令”的名称(然后可以有更多的子命令),例如: ip routeip addr addgit commitgit statusdocker run
  • " short options ": this convention is as old as Unix, maybe even older. 短选项”:这个约定与 Unix 一样古老,甚至可能更老。 An option should be a single alphanumeric character preceded by a - .一个选项应该是一个以-开头的单个字母数字字符。 Multiple consecutive options can be combined.可以组合多个连续选项。 Examples: mkdir -p , ls -la .示例: mkdir -pls -la
  • " long options ": this convention comes from the GNU system. 长选项”:这个约定来自于 GNU 系统。 Options are whole descriptive words preceded by -- .选项是以--开头的完整描述性词。 Example: ls --color示例: ls --color

But I'd like to repeat, because it is very important to understand: this has nothing to do with the shell.但我想重复一遍,因为理解这一点非常重要:这与外壳无关。 These options are processed by docker and docker alone.这些选项由dockerdocker单独处理。 The options would be exactly the same if you called docker from the Windows command line or from Python: no Unix shell in sight anywhere.如果您从 Windows 命令行或 Python 调用docker ,选项将完全相同:在任何地方都看不到 Unix shell。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM