Skip to content

Instantly share code, notes, and snippets.

@bleything
Created September 20, 2010 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleything/588404 to your computer and use it in GitHub Desktop.
Save bleything/588404 to your computer and use it in GitHub Desktop.
# 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