I was looking for a way to enumerate all copies of an executable that are shadowed by the first one in my PATH
. The best I could come up with is a function:
find_all_exec() { for i in ${PATH//:/ }; do find "$i/$1" 2> /dev/null done } $ find_all_exec python /usr/local/bin/python /usr/bin/python
This gets me what I want (though it doesn't handle bash aliases/functions as type
does). I was curious if there's a more built in way?
In Linux, PATH is an environmental variable that tells the shell and other programs which directories to search for executable files. It consists of a list of colon-separated absolute paths to directories containing the executables.
The search path is a list of directories that may contain programs the user wants to run. When the user types the name of a command (program), the directories in the search path are examined to see whether they contain an executable with the requested name. As soon as an executable is found, that program in executed.
Try this builtin command:
which -a python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With