Let $foo
and $bar
be two absolute directory names (output by realpath
). I want to test if either is contained in the other one, at any depth, and execute commands accordingly.
I thought I'd use find
, but its exit status doesn't tell whether something has been found or not. So I've come to:
if [ x$(find -H "$foo" -path "$bar" -printf y -quit) == xy \
-o x$(find -H "$bar" -path "$foo" -printf y -quit) == xy ] ; then
...
fi
Is it correct? Is there something simpler?
Context: my home dir contains an encrypted folder (ecryptfs). I'm writing a script that will sync its argument to the cloud. I don't want the decrypted files to be synced, so I'll test whether the argument overlaps the encrypted folder to unmount the ecryptfs before syncing.