Skip to content

Instantly share code, notes, and snippets.

@liconti
Created November 27, 2012 12:06
Show Gist options
  • Save liconti/4153907 to your computer and use it in GitHub Desktop.
Save liconti/4153907 to your computer and use it in GitHub Desktop.
search backward for a directory from current path
#!/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