Ubuntu bash script: how to split path by last slash?

前端 未结 4 1526
忘掉有多难
忘掉有多难 2020-12-12 22:17

I have a file (say called list.txt) that contains relative paths to files, one path per line, i.e. something like this:

foo/bar/file1
foo/bar/ba         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 23:00

    Great solution from this source

    p=/foo/bar/file1
    path=$( echo ${p%/*} )
    file=$( echo ${p##/*/} )
    

    This also works with spaces in the path!

提交回复
热议问题