为什么shell在单引号内解释字符?

xyz*_*xyz 1 unix linux bash shell scripting

我正在使用bash shell

$cat test
a --b

$grep '--b' test
grep: option `--b' is ambiguous
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

$grep "--b" test
grep: option `--b' is ambiguous
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

$grep '\-\-b' test
a --b
Run Code Online (Sandbox Code Playgroud)

7.7节"引用"中的第7章"输入和输出,文件和命令评估"中的经典shell脚本

"单引号强制shell按字面意思处理引号之间的所有内容".

那么为什么单引号不起作用呢?

Ign*_*ams 6

外壳正在按字面意思对待它们.但shell不对应用程序如何处理它们负责.应用程序决定如何处理--b传递的参数.

  • 或者`grep - --b test` (2认同)