Not a 'deepthroat' programmer at all here, but, couldn't sth like this also work?:
MYPATH="/could/you/please/let/me/keep/the/last/word/ofthis/line"
MYPATHLAST=$(echo "${MYPATH}" | sed -r "s/^(.*)([/])(.*)$/\3/")
echo "${MYPATHLAST}"
Maybe a bit extensive, this, and maybe out of context, but, often useful, sed. It literally takes any last word/part at the end of the given line '(.*)', referenced by group-id 3.
My 'context' is a bash script with zenity '--file-selection --directory' of which the output goes to this rsync:
rsync -rauW --delete --inplace --no-compress --info=progress2 ${EXCL} --mkpath ${SOURCE}/ ${DESTINATION}
(Nevermind the (unquoted) EXCL var, it references possible exludes also rendered through zenity.)
The problem is that '--mkpath' does create a dir by means of a bash script without zenity but not bmo a bash script with zenity --file-selection. You would have to type the new dir at destination from zenity --file-selection, if it doesn't exist. If rsync would create the new dir (the last word of the path-line), I could just select one destination dir upwards with zenity --file-selection to create the new dir with the same name as source dir within it.
So I'm looking for a way to first create the dir with the same name at destination (mkdir -p probably) and then run rsync on it.