The type command

The type command, given the name of any command or commands, gives you information about what kind of command it is:

bash$ type echo
echo is a shell builtin
bash$ type grep
grep is /bin/grep

It identifies shell keyword, too:

bash$ type for
for is a shell keyword

We can define a function and an alias to test that it correctly detects those:

bash$ myfunc() { : ; }
bash$ type myfunc
myfunc is a functionmyfunc (){    :}bash$ alias myalias=:
bash$ type myalias
myalias is aliased to `:'

The type command has a few useful options. If you use the -t option, you can get a single word specifying the command type. This is sometimes useful in scripts:

bash$ type -t echo
builtin
bash$ type -t grep
file

If you use the -a option, you can see ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.