正则表达式 – 使用grep时的报价?

Grep根据正则表达式包围什么样的引号而有所不同.我似乎不明白为什么会这样.这是一个问题的例子:
hamiltont$grep -e show\(  test.txt 
  variable.show();
  variable.show(a);
  variable.show(abc,132);
  variableshow();
hamiltont$grep -e "show\("  test.txt 
grep: Unmatched ( or \(
hamiltont$grep -e 'show\('  test.txt 
grep: Unmatched ( or \(

我只是假设有一些正确的方法用单/双引号括起正则表达式.任何帮助?

FWIW,grep -version返回grep(GNU grep)2.5.1

包含参数的命令行在执行之前由shell处理.你可以使用echo来查看shell的作用:
$echo grep -e show\(  test.txt 
grep -e show( test.txt

$echo grep -e "show\("  test.txt 
grep -e show\( test.txt

$echo grep -e 'show\('  test.txt 
grep -e show\( test.txt

所以没有引号,反斜杠被删除,使得“(”是grep的正常字符(grep认使用基本正则表达式,使用-E来使grep使用扩展正则表达式).

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...