1

From Bash manual

type [-afptP] [name ...]

For each name, indicate how it would be interpreted if used as a command name.

If the -p option is used, type either returns the name of the disk fi le that would be executed, or nothing if -t would not return ‘file’.

The -P option forces a path search for each name, even if -t would not return ‘file’.

If a command is hashed, -p and -P print the hashed value, which is not necessarily the file that appears first in $PATH.

If the -a option is used, type returns all of the places that contain an executable named file . This includes aliases and functions, if and only if the -p option is not also used.

  1. Does file in "If the -a option is used, type returns all of the places that contain an executable named file" mean name instead?

  2. Is -P the same as -ap?

Thanks.

2
  1. Most likely, yes.
  2. Not quite. Just so the use case for -P is clear: -P can be used as a "stronger" -p. For example:

    $ type [ [ is a shell builtin

    $ type -p [

    In the above, type -p [ returns nothing, because type -t [ says builtin (this makes sense, the manual says that -p behaves this way, after all).

    However:

    $type -P [ /usr/bin/[

    The flag -P forces the search to be within the PATH variable, so we get some output.


That said, type -ap and type -P differ, on my system, in the amount of duplicates they output. type -ap echo, for example, produces /usr/bin/echo three times, while type -P echo gives me only one line. This is most likely because /usr/bin is symlinked to a few different places. There's one more (subtle) difference:

If the -a option is used, type returns all of the places that contain an executable named file. This includes aliases and functions, if and only if the -p option is not also used.

So, if I do sudo touch /bin/bogus, type -P bogus happily returns /usr/bin/bogus, while type -ap bogus gives me nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.