为什么引用时无法访问名为“-”的文件?

Jhd*_*doe 2 shell quoting cat

我有一个名为-.

我想显示它的内容。

一种方法是做

cat ./-
Run Code Online (Sandbox Code Playgroud)

因为cat -从标准输入读取。但是,为什么cat "-"cat '-'还解释由shell作为cat -

tri*_*eee 15

外壳在cat看到它们之前删除所有引号。因此,cat -cat "-"cat '-'都得到穿过的阵列['cat', '-']空白标记化后,通配符扩展,并通过壳引用删除。


ctr*_*lor 5

引号由 shell 使用,而不是传递给命令:

例如

cat "hello world" #this passes the single token `hello world`, to `cat`, as argument 1. However the quotes are not passed.
cat "-" # this passes the single token `-`, to `cat`, as argument 1. The same as if no quotes had been used.
Run Code Online (Sandbox Code Playgroud)