I am using Bash. I have some string of paths, like /dir0/dir1/dir2/filename.ext
and I want to extract the string dir2
in bash.
You can assume that the word I want to extract is located between the two last /
characters.
I am trying to combine ##
and %
but with poor results.
What I tried and does not work is cut=${${path%/*}##*/}
.
How can I do that?
Solved but looking for alternatives. My solution is the following:
cut=$(tmp=${path%/*}; echo ${tmp##*/})