Quotes when using grep?

后端 未结 4 558
南旧
南旧 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:16

    The quotes change what grep sees. The backslash (\) in the un-quoted form is processed by the shell, which treats characters after the backslash as special. This happens before grep gets the parameter. grep sees show(. When the quotes (single or double) are used, the shell interprets them as "leave the contents alone", thus grep sees show\( and the \( characters have meaning in grep and it is looking for the closing parenthesis - \).

    BTW: Single and double quote handling is different in how the shell handles shell variables, but there are no shell variables in your example.

提交回复
热议问题