关于用bash中的文字剥离斜线

  • 本文关键字:剥离 文字 于用 bash bash
  • 更新时间 :
  • 英文 :


我在Linux中不好,如果问题非常基本,我很抱歉。

我需要在bash shell上的命令,该命令将返回/home/barco/ext/linux-crp from/home/barco/barco/ext/linux-crp/bin/linux-x86-32/

我读取参数扩展,但无法获得任何提示。

任何帮助都将不胜感激。

尚不清楚您想要的基于什么,但是

> string="/home/barco/ext/linux-crp/bin/linux-x86-32/"; echo "${string%/*/*/*}"
> /home/barco/ext/linux-crp

将返回两个级别的路径(假设路径在/中结束并且足够长)

${parameter%word}
${parameter%%word}
  Remove matching suffix pattern.  The word is expanded to produce
  a pattern just as in pathname expansion.  If the pattern matches
  a  trailing portion 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 posi‐
  tional 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.

相关内容

  • 没有找到相关文章