1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/bin/sh set -eu if [ ! "${1:-}" ]; then exit 1 fi BASEDIR="$(dirname "$1")" while read -r glob; do cd "$BASEDIR" while [ "$PWD" != "/" ]; do set -- "$glob" if [ -e "$1" ]; then echo "$PWD" exit 0 fi cd .. done done exit 1