我正在使用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
第7.7节“输入和输出,文件和命令评估”中的经典shell脚本手册第7.7节“引用说”
“单引号强制shell按字面意思处理引号对之间的所有内容。”
那为什么单引号不能在上面工作?
答案 0 :(得分:6)
shell 按字面意思对待它们。但是shell不对应用程序如何处理它们负责。由应用程序决定如何处理作为参数传递的--b
。
答案 1 :(得分:2)
大多数gnu实用程序会在--options
之后忽略--
,因此您可能需要执行grep -- --b test
。因为你标记了你的问题linux
,你很可能有gnu grep。