I'm not sure I fully understand the question and the context. But maybe this works:
#!/bin/bash
foo="$(realpath "...")"
bar="$(realpath "...")"
if [[ $foo = $bar/* || $bar = $foo/* ]]; then
echo "Overlap"
fi
foo="$(realpath "...")"
bar="$(realpath "...")"
if [[ $foo = $bar/* || $bar = $foo/* ]]; then
echo "Overlap"
fi
Note that this won't work if one tree is sym-linked into the other.