【发布时间】:2021-02-13 09:53:34
【问题描述】:
目标是匹配文本中的单引号或双引号单词。
'foo'
"bar"
'buz"
# text
在经典 Shell 脚本(脚本 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
【问题讨论】:
标签: shell double-quotes single-quotes