0

Is there a builtin way to ask a current shell "find me all of the possible matches for a given command in the PATH?"

I realize that I could write a script that:

  1. expands the current PATH
  2. checks for the existence of a given command in all of these locations
  3. prints the results

but I've also found that linux very often has builtin magical shortcuts for stuff like this

Another way to consider this use case is as a general answer to something like "if I type which [whatever], how do I know programmatically what happens if the first hit in the path is NOT there?" ... and so on.

ljwobker
  • 529

1 Answers1

2

This answer isn't Linux-specific, but if you're using the bash or zsh shells, you can use:

type -a command

to see all the places the shell could potentially find command.

Jim L.
  • 7,997
  • 1
  • 13
  • 27
  • 1
    Also in ksh93 and fish. But not that it's limited to commands in $PATH, it will also report aliases, functions, keywords... With zsh, you can do type -pa (whence -pa for only their paths). Some which implementations can do it with which -a (which -pa with the builtin which of zsh) – Stéphane Chazelas Mar 03 '23 at 20:25