如何使用bash从除第一个文件夹之外的所有路径获取?
例如
从
'a/b/d/e'
得到
'b/d/e'
现在我用蟒蛇做这个
$ 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#*/}"