加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 06:30:18 所属栏目:百科 来源:网络整理
导读:Grep根据正则表达式包围什么样的引号而有所不同.我似乎不明白为什么会这样.这是一个问题的例子: hamiltont$grep -e show( test.txt variable.show(); variable.show(a); variable.show(abc,132); variableshow();hamiltont$grep -e "show(" test.txt 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使用扩展正则表达式).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读