如何使用 bash 从除第一个文件夹之外的所有路径获取

用户3313834

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#*/}"

居鲁士

使用 bash 及其参数扩展

x='a/b/d/e'
echo "${x#*/}"

输出:

日/日/日

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何删除数组中除第一个索引之外的所有内容?

如何加入数组中除第一个元素之外的所有元素?

如何循环遍历列表中除第一个之外的所有项目

如何对齐除第一个 2 之外的所有列?

如何将除第一个参数以外的所有参数传递给第二个bash脚本?

删除除第一个使用递归之外的所有数字

使用纯CSS隐藏除元素的第一个孩子之外的所有孩子

Bash命令从每个文件夹递归获取第一个和最后一个文件

如何从所有子文件夹中取出文件并将其移至第一个文件夹

如何使用 JQuery 删除除第一个 div 之外的所有子 div 元素?

如何使用bash从文件夹中选择一个随机文件而无需重复?

bash列出当前文件夹中的子文件夹没有得到预期的结果[仅提供第一个文件夹]

如果第一个2nd和3rd字段相同,如何使用Sort或另一个bash cmd从所有行中获取1行

如何使用Bash搜索路径中包含给定子字符串的所有文件/文件夹?

Bash脚本编写并使用TAR归档文件夹,如何在一个文件夹中抓取5个最新的文件夹?

如何检查文件每一行上的所有路径在Bash中是否为有效路径?

jQuery / JavaScript:如何删除第一个<li>中除<a> text </a>之外的所有元素

如何测试选择器中除 Jest 中的第一个孩子之外的所有孩子

使用webdriver关闭除第一个标签/主标签之外的所有打开的标签

使用打字稿从数组中提取除第一个之外的所有元素类型

如何在vscode中排除除一个文件夹以外的所有文件夹?

将文件中每行的除第一个','以外的所有内容更改为“ <COMMA>”(bash)

如何忽略除一个以外的所有dist文件夹?

如何从另一个脚本的文件夹中获取多个bash脚本,以便我可以使用两个脚本中的函数?

在mac上的bash中删除除一个文件之外的所有文件

处理除第一个参数以外的所有参数(在bash脚本中)

如何使用 bash/awk 将每个文件的日期显示为每行的第一个元素?

如何压缩 Bash 中的所有子文件夹?

如何删除目录中除最新的 10 个隐藏文件夹之外的所有文件夹