Here is a quick and dirty sample script to do what you want in practice:
#!/bin/sh
IFS=:
for i in $PATH; do
for j in "$i"/$1; do
[ -f "$j" ] && [ -x "$j" ] && printf '%s\n' "$j"
done
done
Save this as e.g. whichglob
and make it executable. Sample run:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin
$ ./whichglob grep*
/usr/bin/grepdiff
/usr/bin/grep-excuses
/usr/bin/grepjar
/bin/grep
Actually all the functionality in which
(-a
, exit statuses, multiple file match inputs) can be easily added in this shell script context as well, but I leave that as an exercise for the reader.
gcc
and press Tab twice to have it autocompleted. Does that work for you or what else is your situation? Meaning, why would you need this?*
is expanded before the program is executed. That means the interpretation does not depend on the program. In this case,gcc*
is expanded in the current directory. That's why it doesn't work./usr/bin/gcc
. and by usingbrew
installed gcc is placed/usr/local/bin/gcc-4.x
. I wanted to know there are othergcc-*
programs. Of course I can usefind
, but it takes some time.