我找到了如下语法。
${VARIABLE##*/}
##*/
的含义是什么?
我知道*/
中ls */
的含义,但不知道上面的语法是什么。
答案 0 :(得分:0)
来自man bash
:
${parameter#word}
${parameter##word}
Remove matching prefix pattern. 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 pat‐
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parame‐
ter in turn, and the expansion is the resultant list. If param‐
eter 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.
答案 1 :(得分:0)
这个例子将说清楚:
VARIABLE='abcd/def/123'
echo "${VARIABLE#*/}"
def/123
echo "${VARIABLE##*/}"
123
##*/
正在从输入开始中删除 /
的最长匹配。#*/
正在从输入开始中删除 /
之后的最短匹配。 PS:在Unix shell中使用所有大写变量名称并不是很好的做法。最好使用variable
代替VARIABLE
。