Created
January 7, 2012 04:17
-
-
Save hydra35/1573775 to your computer and use it in GitHub Desktop.
archlinux's basedir aware `which`
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
pathlookup() { | |
# a basedir aware 'type -P' (or which) for executables | |
# $1: binary to find | |
local path= | |
local -a paths= | |
IFS=: read -r -a paths <<< "$PATH" | |
for path in "${paths[@]}"; do | |
[[ ${path:0:1} = [.~] ]] && continue | |
if [[ -x $BASEDIR$path/$1 ]]; then | |
printf '%s' "$BASEDIR$path/$1" | |
return 0 | |
fi | |
done | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment