如何使用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#*/}"
的作用并没有太大帮助