Created
September 12, 2013 12:46
-
-
Save tlatsas/6536715 to your computer and use it in GitHub Desktop.
return the location of a binary by searching in $PATH
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
#!/bin/bash | |
[[ -z $1 ]] && { echo "usage: inpath <filename>"; exit 1; } | |
for path in ${PATH//:/ }; do | |
if [[ -e "$path/$1" ]]; then | |
echo "$path/$1" && exit 0 | |
fi | |
done | |
echo "$1 not in \$PATH" && exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment