I have seen many tutorials that use a --
after commands. Something like this:
command --
What does this --
mean?
I have seen many tutorials that use a --
after commands. Something like this:
command --
What does this --
mean?
The --
is used to indicate the end of command line options. This enables you to use arguments starting with --
. For example, if you create a file called --foo
:
$ > '--foo'
$ ls
--foo
And then try to delete it, rm
will think you're giving it an argument:
$ rm --foo
rm: unrecognized option '--foo'
Try 'rm ./--foo' to remove the file '--foo'.
Try 'rm --help' for more information.
One way around this is to use --
:
$ rm -- --foo
This is common practice and recommended by POSIX, so it's supported by many programs.
rm
program and of many POSIX-compliant utilities. See Guideline 10. To actually check that it isn't Bash doing the work (and that wouldn't make sense), just create a small script with just printf '> %s <\n' "$@"
and launch it with --
.
Jul 2, 2016 at 17:02
--
, but, of course, that's simply because the relevant Perl module (getopts
) also supports it. You're quite right, I just quickly searched man bash
, saw the section I had quoted but failed to notice that it was in the "command line options" section. Thanks for the correction, answer edited.
Most commands will use a -- to tell the command that further parameters should be treated differently. One example is the rm -- --filename noted above. Another example, a script like 'startx' will interpret itself everything before -- , and pass everything after it to the X server.