How does variable substitution to extract the current folder's name work in Bash?
我使用下面的脚本获取bash中当前文件夹的名称:
1 | ${PWD##*/} |
这是我在这个问题中看到的一个技巧。然而,我并不真正理解语法
有人能解释一下吗?如果这是一个愚蠢的问题,请提前道歉!
GNU的bash手册从https://www.gnu.org /软件/ bash手册/ HTML /节点/ shell-parameter-expansion.html _
${parameter#word}
${parameter##word}The word is expanded to produce a pattern just as in filename expansion (see Filename Expansion). If the pattern matches the beginning of the expanded 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.
简单的解释
假设,参数,
Word是一
和GNU的bash手册
the longest matching pattern (the ‘##’ case) deleted
这给你
PS:没有愚蠢的问题