Quantcast
Channel: How to get string between the last two "/" symbols - Super User
Viewing all articles
Browse latest Browse all 5

Answer by AFH for How to get string between the last two "/" symbols

$
0
0

You need to do the parsing in stages:-

path=/dir0/dir1/dir2/filename.ext
dir=${path%/*}
lastdir=${dir##*/}

By attempting to combine both parsing operations, you were attempting to use a string instead of a variable in the second expansion: this is not supported.

Note that you can use the same variable name for both dir and lastdir, eg:-

cut=${path%/*}; cut=${cut##*/}

You haven't said that your shell is bash, but I have assumed this from your code sample.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images