Difference between revisions of "Type command"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 45: Line 45:
 
Sample Outputs:
 
Sample Outputs:
 
<pre>/bin/date</pre>
 
<pre>/bin/date</pre>
 +
==type command==
 +
===type -a Command Examples===
 +
    If the -a flag is used, `type' displays all of the places that contain
 +
    an executable named `file'.  This includes aliases, builtins, and
 +
    functions, if and only if the -p flag is not also used.

Revision as of 12:04, 12 September 2009

The type command is used to find out if command is builtin or external binary file. It also indicate how it would be interpreted if used as a command name.

Find Out Command Type (-t option)

If the -t option is used, it will print a single word which is one of the following

  • alias (command is shell alias)
  • keyword (command is shell reserved word)
  • function (command is shell function)
  • builtin (command is shell builtin)
  • file (command is disk file)

type -t Command Examples

Try the following examples:

Command Output Meaning
type -t ls alias ls command is alias which can be verified by typing the alias command itself at a shell prompt:
alias
type -t date file date command is a disk file (external command), which can be verified by issued the which date command at a shell prompt:
which date
type -t xrpm function xrpm is a user defined function.
type -t if keyword if is a shell reserved word, which is used for flow control.
type -t pwd builtin pwd is a shell builtin command.

Return Command Name Type (-p option)

The -p option is used to find of the name of the disk file (external command) would be executed by the shell. It will return nothing if it is not a disk file.

type -p Command Examples

Type the following command at a shell prompt:

type -p ls

Nothing is return as ls is aliased on my CentOS Linux system. You can verify this by typing the following command:

type -t ls

However, the following should return full disk path to date command:

type -p date

Sample Outputs:

/bin/date

type command

type -a Command Examples

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