Created
September 15, 2019 08:08
-
-
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
This file contains hidden or 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
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