- 论坛徽章:
- 0
|
原帖由 leyyer 于 2007-8-28 18:12 发表 ![]()
bash ?
a=/home/me/a.out
echo ${a%/*}
强哦……找到了相关解释(man bash),顶一下:
${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 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.
${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 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/pattern/string}
${parameter//pattern/string}
The pattern is expanded to produce a pattern just as in pathname
expansion. Parameter is expanded and the longest match of pat-
tern against its value is replaced with string. In the first
form, only the first match is replaced. The second form causes
all matches of pattern to be replaced with string. 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 parameter in turn, and the expan-
sion is the resultant list. If parameter is an array variable
subscripted with @ or *, the substitution operation is applied
to each member of the array in turn, and the expansion is the
resultant list. |
|