An even more general version that allows using
while [[ "$path" != "/" ]];
find "$path" -maxdepth 1 -mindepth 1 "$@"
# Note: if you want to ignore symlinks, use "$(realpath -s $path/..)"
path="$(readlink -f $path/..)"
For example (assuming the script is saved as
find_up.sh some_dir -iname "foo*bar" -execdir pwd \;
...will print the names of all of
some_dir's ancestors (including itself) up to
/ in which a file with the pattern is found.
readlink -f the above script will follow symlinks on the way up, as noted in the comments. You can use
realpath -s instead, if you want to follow paths up by name ("/foo/bar" will go up to "foo" even if "bar" is a symlink) - however that requires installing
realpath which isn't installed by default on most platforms.