我已经学习了很长一段时间了,但我仍然无法理解手册中的%(pattern-pair(s))
。任何人都可以给出一个简单有意义的例子吗?
A pattern of the form %(pattern-pair(s)) is a sub-pattern that can be
used to match nested character expressions. Each pattern-pair is a two
character sequence which cannot contain & or |. The first pattern-pair
specifies the starting and ending characters for the match. Each sub-
sequent pattern-pair represents the beginning and ending characters of
a nested group that will be skipped over when counting starting and
ending character matches. The behavior is unspecified when the first
character of a pattern-pair is alpha-numeric except for the following:
D Causes the ending character to terminate the search for
this pattern without finding a match.
E Causes the ending character to be interpreted as an
escape character.
L Causes the ending character to be interpreted as a quote
character causing all characters to be ignored when look-
ing for a match.
Q Causes the ending character to be interpreted as a quote
character causing all characters other than any escape
character to be ignored when looking for a match.
答案 0 :(得分:0)
我认为它对JSON解析很有用:
json='{"foo":{"bar":"baz"} }'
#remove all quoted values nested in punctuation except the first
jsonroot=${json%%[[:punct:]][[:punct:]]%(\"\")*}
#remove initial curly
jsonroot=${jsonroot#?}