Mat*_*hen 51
这取决于.如果您使用常规grep,则不会转义:
echo '(foo)'|grep '(fo*)'
Run Code Online (Sandbox Code Playgroud)
如果要将括号用作分组,则实际上必须转义.
如果使用扩展正则表达式,则执行转义:
echo '(foo)'|grep -E '\(fo*\)'
Run Code Online (Sandbox Code Playgroud)
Dav*_*rby 23
如果要搜索字符串"init()",请使用fgrep "init()"或grep -F "init()".
这两个都将进行固定的字符串匹配,即将模式视为要搜索的纯字符串而不是正则表达式.我相信它也比正则表达式搜索更快.