Pure bash, without hard coding the answer
basenames()
{
local d="${2}"
for ((x=0; x<"${1}"; x++)); do
d="${d%/*}"
done
echo "${2#"${d}"/}"
}
- Argument 1 - How many levels do you want to keep (2 in the original question)
- Argument 2 - The full path
Taken from vsi_common(original version)