![使用 ag / awk 进行搜索时如何使用 '(' 标记?](https://linux22.com/image/63539/%E4%BD%BF%E7%94%A8%20ag%20%2F%20awk%20%E8%BF%9B%E8%A1%8C%E6%90%9C%E7%B4%A2%E6%97%B6%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20'('%20%E6%A0%87%E8%AE%B0%EF%BC%9F.png)
$ ag findVersions( src/java/com/google
-bash: syntax error near unexpected token `('
我尝试引用它,逃避它,两者都不合适。
$ ag findVersions\( src/java/com/google
ERR: pcre_compile failed at position 13. Error: missing )
$ ack findVersions\( src/java/com/twitter
Invalid regex 'findVersions(':
Unmatched ( in regex; marked by <-- HERE in m/findVersions( <-- HERE / at /opt/bin/ack line 2989.
答案1
由于第一个参数是正则表达式,因此您必须:转义正则表达式特殊字符,并保护它免受 shell 的影响
ag 'findVersions\(' src/java/com/google