#! /bin/bash
# Last edited on 2021-07-31 14:22:15 by jstolfi

# Checks whether the current directory's pathname ends with a specific tail.

target="$1"; shift  # One or more dir names separated by "/"

obj="${target}"
cur="${PWD}"

while [[ "/${obj}" != "/" ]]; do
  tobj="${obj##*/}"
  tcur="${cur##*/}"
  if [[ "/${tobj}" != "/${tcur}" ]]; then
    echo "** wrong directory, should be in */${target}" 1>&2 ; exit 1
  fi
  obj="${obj%${tobj}}";  
  cur="${cur%${tcur}}"; 
  #echo "${obj}" "${cur}" 1>&2 
  obj="${obj%/}"
  cur="${cur%/}"
  #echo "${obj}" "${cur}" 1>&2 
done
