Last active
March 8, 2020 00:29
-
-
Save mscalora/3f9756735036c27b7b13b9063c054d1d to your computer and use it in GitHub Desktop.
search up a directory tree for multiple filenames
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 | |
search_all_up() { | |
# extended from https://stackoverflow.com/a/19011599/370746 | |
local look=${PWD%/} | |
while [[ -n $look ]]; do | |
for name in $@ ; do | |
[[ -e $look/$name ]] && { | |
printf '%s\n' "$look/$name" | |
return | |
} | |
done | |
look=${look%/*} | |
done | |
[[ -e /$1 ]] && echo / | |
} | |
search_all_up one.txt two.txt three.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment