bash - grep 中双引号中的减号被识别为一个选项

标签 bash grep

如果我在写

grep -v "-NO" file

它说

grep: invalid option -- 'N'

所以我需要编写 grep -v -- "-NO"filegrep -v "\-NO"file

但是,如果 - 在双引号中,为什么它会将其识别为选项?

最佳答案

在将参数传递给 grep 之前,shell 会在一个名为 Quote Removal 的步骤中删除引号。 .另见 Simple Command Expansion .所以,实际上,grep 永远不会看到这些引号。

关于bash - grep 中双引号中的减号被识别为一个选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33188481/

相关文章:

mysql - 如何检查MySQL表中的最后一行是否有所需的值?

linux - 调度操作 bash

bash - 无法获得 imgur v3 api 请求以使用 curl 或其他 bash 实用程序进行授权

regex - Bash - 从不包含特定模式的文件中获取行

c++ - 如何grep 'vector'而不是 'std::vector'

linux - 为什么 grep 找不到整数 * 2?

linux - 使用 Bash 在 "sudo -i"之后切换回之前的用户

linux - 如何在文件中搜索多行并在 bash/dash 中注释这些行

linux - 将变量传递到 BASH 函数时出现“未找到命令”,我是否引用错误?

linux - 期望脚本错误发送 : spawn id exp4 not open while executing "send "password""