Double dash:
- The double dash “–” means end of command line flags i.e. it tells the preceding command not to try to parse what comes after command line options.
- It is actually part of the POSIX standard that — can be used to separate options from other arguments, so you will see it on commands like cp and mv (which are not part of Bash).
- — works to separate options from regular expressions in grep, but the canonical way is to use -e/–regexp
Example use:
you want to grep a file for the string -v – normally -v would be considered as the option to reverse the matching meaning (only show lines that do not match), but with — you can grep for string -v like this:
[pastacode lang=”bash” manual=”grep%20–%20-v%20file%20″ message=”Bash Code” highlight=”” provider=”manual”/]A double dash ( — ) is used in bash built-in commands and there are more other commands to signify the end of command options, after which only positional parameters are accepted
Example:
Suppose you have a file named path/to/file.txt in my Git repository, and you want to revert changes on it.
[pastacode lang=”bash” manual=”git%20checkout%20path%2Fto%2Ffile.txt%0A” message=”Bash Code” highlight=”” provider=”manual”/]Now suppose that the file is named master…
[pastacode lang=”bash” manual=”git%20checkout%20master%0A” message=”Bash Code” highlight=”” provider=”manual”/]Whoops! That changed branches instead. The — helps to separate the tree you want to check out from the files you want to check out.
[pastacode lang=”bash” manual=”git%20checkout%20–%20master%0A%0A” message=”Bash Code” highlight=”” provider=”manual”/]