双号标志和命令的含义

时间:2013-09-07 16:13:47

标签: unix

Say file的值为:/usr/bin/ls

${file##/*/}

在以下命令之后,输出仅为ls

似乎无法理解## ..

的含义

这里发生了什么?

1 个答案:

答案 0 :(得分:2)

该表达式从/*/的值的开头删除与模式file匹配的任何内容。

man bash

   ${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.