Skip to content

Instantly share code, notes, and snippets.

@dajulia3
Created September 15, 2019 08:08
Show Gist options
  • Save dajulia3/f43b9174746d4ef6404c8a8883a29cf1 to your computer and use it in GitHub Desktop.
Save dajulia3/f43b9174746d4ef6404c8a8883a29cf1 to your computer and use it in GitHub Desktop.
Bash script to find the parent directory of a file or dir that is located above the working dir in the hierarchy
find_parent_upwards() {
local look=${PWD%/}
while [[ -n $look ]]; do
[[ -e $look/$1 ]] && {
printf '%s\n' "$look"
return
}
look=${look%/*}
done
[[ -e /$1 ]] && echo /
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment