type

Displays the type of the specified command.

Summary

  type [-afptP] name [name ...]

The main purpose

Options

-a: Search and display all executable file paths containing name in the environment variable PATH; when the '-p' option is not given at the same time, if name exists in aliases, keywords, functions, and built-in information, then displayed together.
-f: Exclude searching for shell functions.
-p: If name does not return 'file' when executing 'type -t name', then nothing will be returned; otherwise, the executable file path will be searched and returned in the environment variable PATH.
-P: Even if the name to be searched is one of alias, built-in, or function, the executable file path will still be searched and returned in the environment variable PATH.
-t: Returns a word according to the type of name (alias, keyword, function, built-in, file), otherwise returns a null value.

Parameters

name: The command to be found, which can be multiple.

return value

Returns success when the specified command can be found, otherwise returns failure if it is not found.

example

The following example assumes that the '~/.bashrc' file defines the following:

alias ls='ls --color=auto'
mybash(){ vim ~/.bashrc; }

Moreover, enable is not used in the execution environment to disable built-in commands.
type -a mybash
# output
mybash is a function
mybash()
{
     vim ~/.bashrc
}

type -a -f mybash
# Output (because the function is excluded, an error is reported)
bash: type: mybash: not found

type -a -p mybash
# The output is empty (nothing is returned because the function is excluded)

type -a ls
# output
ls is aliased to `ls --color=suto'
ls is /usr/bin/ls
ls is /bin/ls

type -a -p ls
# output
/usr/bin/ls
/bin/ls
# '-f' will not affect the scope of '-P'. '-f' is not recommended to be used with '-p'.
# Note: printf is both a built-in command and an executable file (GNU coreutils), and is treated as a built-in first.

type -p printf
# Output is empty

type -P printf
# output
/usr/bin/printf
/bin/printf
# If there are multiple types, output the type with the highest priority.

type -t ls
# output
alias

type -t for
# Output (bash keyword)
keyword

type -t mybash
# output
function

type -t -f mybash
# Output null value

type -t printf
# Output (bash built-in priority is high)
builtin

type -t chmod
# output
file

Notice