|
发表于 2010-6-30 14:12:36
|
显示全部楼层
模式替换
${1//[^0-9]/}是模式替换。格式是${parameter/pattern/string}。这里的parameter是1,pattern是"/^[0-9]",string被省略了,我觉得解释为空。pattern以斜杠开头是说在$parameter中所有的匹配都替换为string。所以${1//[^0-9]/}就是将位置变量$1中所有的非数字([^0-9])替换为空。
参见man bash 中 EXPANSION小节。
${parameter/pattern/string}
Pattern substitution. The pattern is expanded to produce a pattern just as in pathname expansion.
Parameter is expanded and the longest match of pattern against its value is replaced with string.
If pattern begins with /, all matches of pattern are replaced with string. Normally only the
first match is replaced. If pattern begins with #, it must match at the beginning of the expanded
value of parameter. If pattern begins with %, it must match at the end of the expanded value of
parameter. If string is null, matches of pattern are deleted and the / following pattern may be
omitted. If parameter is @ or *, the substitution operation is applied to each positional parame‐
ter in turn, and the expansion is the resultant list. If parameter is an array variable sub‐
scripted with @ or *, the substitution operation is applied to each member of the array in turn,
and the expansion is the resultant list. |
|