目标是匹配文本中的单引号或双引号。
'foo'
"bar"
'buz"
# text
在名为Classic Shell Scripting(脚本1)的书中的bash脚本中,需要转义引号。怎么做?
#! /bin/sh -
grep \(["']\).*\1 text
# script 1
替代解决方案(脚本2)是。
#! /bin/sh -
grep -e "'.*'" -e '".*"' text
# script 2
@William Pursell的确切解决方案(脚本3)更紧凑。
#! /bin/sh -
grep '\(["'"']\).*\1" text
# script 3
我可能对这个问题有误解,但似乎您在问如何正确处理引号。做就是了:
grep '\(["'"']\).*\1.*\1"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句