在搜索 unix 问题时,我遇到了以下字符串拆分正则表达式语句:
string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"
str1=${string%%;*}
str2=${string##*;}
Result:
str1=abc@hotmail.com
str2=uvw@yahoo.com
我不明白第二个表达式(str2)。可以请人帮忙。
谢谢
从bash
手册中,在Parameter Expansion
:
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the
value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pat-
tern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted. If parameter is @ or *, the pattern
removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter
is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in
turn, and the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trailing portion of
the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest
matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If
parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the
array in turn, and the expansion is the resultant list.