Remove part of path on Unix

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

    Using ${path#/path/to/file/drive/} as suggested by evil otto is certainly the typical/best way to do this, but since there are many sed suggestions it is worth pointing out that sed is overkill if you are working with a fixed string. You can also do:

    echo $PATH | cut -b 21-
    

    To discard the first 20 characters. Similarly, you can use ${PATH:20} in bash or $PATH[20,-1] in zsh.

提交回复
热议问题