Remove part of path on Unix

前端 未结 7 1069
滥情空心
滥情空心 2020-11-30 21:56

I\'m trying to remove part of the path in a string. I have the path:

/path/to/file/drive/file/path/

I want to remove the first part /

相关标签:
7条回答
  • 2020-11-30 22:34

    Pure bash, without hard coding the answer

    basenames()
    {
      local d="${2}"
      for ((x=0; x<"${1}"; x++)); do
        d="${d%/*}"
      done
      echo "${2#"${d}"/}"
    }
    
    • Argument 1 - How many levels do you want to keep (2 in the original question)
    • Argument 2 - The full path

    Taken from vsi_common(original version)

    0 讨论(0)
提交回复
热议问题