bash中看到这样的命令,
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs 黄色部分,| 这个是管道操作符,表示前面命令的输出作为后面的命令的输入。 "bash -" bash 跟一个短杠的作用是什么呢?
For a command, if using-
as an argument in place of a file name will mean STDIN or STDOUT.
---------------------------------------------------------
Generally:
-
means to read the argument/content from STDIN (file descriptor 0)--
means end of command options, everything follows that are arguments
Why needed:
About -
:
$ echo foobar | cat -
foobar
Although cat
can read content from STDIN without needing the -
, many commands need that and their man
pages mention that explicitly.
Now about --
, I have created a file -spam
, let's cat
the file:
$ echo foobar >-spam
$ cat -spam
cat: invalid option -- 'p'
Try 'cat --help' for more information.
$ cat -- -spam
foobar
Without --
, cat
takes s
, p
, a
, m
all as it's options as they follow -
, --
explicitly indicates the end of option(s), after that -spam
is taken as a file name.