As explained in this question, we can get name of current working directory. But how to get last but one directory name?
Scenario:
# working directory /etc/usr/abc/xyz.txt
printf '%s\n' "${PWD##*/}" #prints abc
#i want to print usr
printf '%s\n' "%{PWD##*/-1}" #prints me whole path
Suggest me how to do this.
Thanks in advance.