简体   繁体   中英

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. 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. They can be combined; eg ls -l -a is equivalent to ls -la .

By GNU convention , long options are preceded by two dashes. 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.

What does “--” and “-” mean on any Unix Shell?

-- and - have no meaning in the shell.

These are simply parameters for the docker command.

If you want to know what meaning they have for the docker command, you will have to look them up in man docker .

There is absolutely no difference between --name , -e , foo , or --!--!--!-- . They are all simply parameter names, the - is simply as much part of the name as the n or the e .

--name is the name of a parameter, -e is the name of a parameter, run is the name of a parameter.

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.

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:

  • " 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 .
  • " short options ": this convention is as old as Unix, maybe even older. An option should be a single alphanumeric character preceded by a - . Multiple consecutive options can be combined. Examples: mkdir -p , ls -la .
  • " long options ": this convention comes from the GNU system. Options are whole descriptive words preceded by -- . Example: 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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