##*/在unix中的含义是什么?

##*/在unix中的含义是什么?,unix,Unix,我发现语法如下 ${VARIABLE##*/} ##*/在这本书中是什么意思 我知道ls*/中*/的含义,但不知道上述语法的作用。来自man bash: ${parameter#word} ${parameter##word} Remove matching prefix pattern. The word is expanded to produce a pattern just as in pathname expansion. If

我发现语法如下

${VARIABLE##*/}
##*/
在这本书中是什么意思


我知道
ls*/
*/
的含义,但不知道上述语法的作用。

来自
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.

这个例子将说明:

VARIABLE='abcd/def/123'

echo "${VARIABLE#*/}"
def/123

echo "${VARIABLE##*/}"
123
  • ##*/
    从输入的开始中去掉任何后跟
    /
    最长匹配
  • .*/
    是从输入的开始中去掉任何紧跟
    /
    最短匹配

PS:在Unix shell中使用所有大写变量名被认为不是很好的做法。最好使用
variable
而不是
variable

这个问题似乎离题了,因为它是关于Unix使用的,属于可能的重复