Quotes when using grep?

后端 未结 4 557
南旧
南旧 2021-02-02 13:15

Grep acts differently depending on what kind of quotes I surround the regex with. I can\'t seem to get a clear understanding of why this is. Here is an example of the problem:

4条回答
  •  一整个雨季
    2021-02-02 14:13

    In order:

    grep -e show( test.txt
    

    does not work, because the shell interprets the ( as special, a parenthesis, not just a character, and can't find the closing ).

    These both work:

    grep -e 'show(' test.txt
    grep -e "show(" test.txt
    

    because the shell treats the quoted text as just text, and passes it to grep.

    These do not work:

    grep -e 'show\(' test.txt
    grep -e "show\(" test.txt
    

    because the shell passes show\( to grep, grep sees \( as special, a parenthesis, not just a character, and can't find the closing \).

提交回复
热议问题