Remove part of path on Unix

前端 未结 7 1232
滥情空心
滥情空心 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:16

    If you don't want to hardcode the part you're removing:

    $ s='/path/to/file/drive/file/path/'
    $ echo ${s#$(dirname "$(dirname "$s")")/}
    file/path/
    

提交回复
热议问题