bash 如何从除第一个文件夹之外的所有路径获取?
例如
从'a/b/d/e'
得到'b/d/e'
现在我用 pythonpy 做到这一点
$ pip install pythonpy
$ echo 'a/b/d/e' | py -x '"/".join(x.split("/")[1:])'
b/d/e
$
#Cyrius 解决方案运行良好::
$ x='a/b/d/e'
$ echo "${x#*/}"
b/d/e
$
但在阅读Parameter Expansion 后,唯一相关的例子${parameter#...}
是:
${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.
这对我理解什么是由 "${x#*/}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句