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
  • 499
  • 4
  • 14
  • Related: [Why not use "which"? What to use then?](https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then) – steeldriver Mar 03 '23 at 19:50

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,188
  • 1
  • 13
  • 25
  • 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