Created
September 20, 2010 18:41
-
-
Save bleything/588404 to your computer and use it in GitHub Desktop.
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
# A faster version of which, that also prints ALL versions in your PATH, | |
# and accepts wildcards, e.g.: which '*uu*'. Silent if nothing found. | |
# Only works if test -x works... | |
# Modifyed by davida to only return the first match | |
function which() { | |
case $# in | |
0) echo Usage: which cmd ...; return 1;; | |
esac | |
dirs=`echo $PATH|sed 's/^:/. / | |
s/:$/ ./ | |
s/::/ . /g | |
s/:/ /g'` | |
for cmd; do | |
for d in $dirs; do | |
for file in $d/$cmd ; do | |
if test -x $file -a ! -d $file ; then | |
echo $file | |
fi | |
done | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment