Linux命令行参数中“--”(两个减号)参数的作用

据bash用户手册,两个减号参数“--”的说明是:

A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.
If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands. If bash is invoked in this fashion, $0 is set to the name of the file, and the positional parameters are set to the remaining arguments. Bash reads and executes commands from this file, then exits. Bash's exit status is the exit status of the last command executed in the script. If no commands are executed, the exit status is 0. An attempt is first made to open the file in the current directory, and, if no file is found, then the shell searches the directories in PATH for the script.

即:“--”用来指示本命令行“选项”参数的结束,所有位于“--”后面的参数代表“文件名”或执行此“文件”需要的“参数”。如:

  • git checkout -- 文件1 文件2 文件3
  • lua -E -- 脚本.lua 参数1 参数2 参数3

这样应该就非常明了了。

发表于:2016年01月03日 ,阅读量:862 ,标签:linux

版权声明:若非特别注明,本站所有文章均为作者原创,转载请务必注明原文地址。