In this tutorial we need to execute the following command:
# curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
What does the last -
(hyphen) after bash
mean?
I've seen a lot of commands with this, and couldn't find myself a logical explanation and neither find how to reformulate a google search for it. Is it the output of the piped command?
Best Answer
Bash behaves in somewhat non-standard way when it comes to
-
.POSIX says:
And
But then
man 1 bash
reads:So for Bash
-
means neither standard input nor a file, hence somewhat non-standard.Now your particular case:
I suspect the author of this command may not realize
-
is equivalent to--
in this case. I suspect the author wanted to make surebash
will read from its standard input, they expected-
to work according to the guideline 13.But even if it worked according to the guideline,
-
would be unnecessary here becausebash
detects when its standard input is a pipe and acts accordingly (unless-c
is given etc.).Yet
-
doesn't work according to the guideline, it works like--
. Still--
is unnecessary here because there are no arguments after it.In my opinion the last
-
changes nothing. The command would work without it.To see how
--
and-
can be useful in general, study the example below.cat
in my Kubuntu obeys both guidelines and I will use it to demonstrate usefulness of-
and--
.Let a file named
foo
exist. This will print the file:Let a file named
--help
exist. This won't print the file:But this will print the file named
--help
:This will concatenate the file named
--help
with whatever comes from the standard input:It seems you don't really need
--
, because you can always pass./--help
which will be interpreted as a file for sure. But considerwhen you don't know beforehand what the content of the variable is. You cannot just prepend
./
to it, because it may be an absolute path and./
would break it. On the other hand it may be a file named--help
(because why not?). In this case--
is very useful; this is a lot more robust command: