Created
November 27, 2012 12:06
-
-
Save liconti/4153907 to your computer and use it in GitHub Desktop.
search backward for a directory from current path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
die () { | |
echo >&2 "$@" | |
exit 1 | |
} | |
[ "$#" -eq 1 ] || die "1 argument required, $# provided" | |
DIRNAME=$1 | |
while [ ! -d ${DIRNAME} ] && [ "${PWD}" != "/" ]; do | |
cd .. | |
done | |
[ "${PWD}" = "/" ] && die "dir '${DIRNAME}'' not found!" | |
echo "${PWD}/$DIRNAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment