Difference between revisions of "Type command"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 1: Line 1:
 
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.
 
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===
+
==Find Out Command Type (-t option)==
 
If the -t option is used, it will print a single word which is one of the following
 
If the -t option is used, it will print a single word which is one of the following
 
* alias (command is shell alias)
 
* alias (command is shell alias)
Line 7: Line 7:
 
* builtin (command is shell builtin)
 
* builtin (command is shell builtin)
 
* file (command is disk file)
 
* file (command is disk file)
 +
===type -t Command Examples===
 
Try the following examples:
 
Try the following examples:
 
{| style="cellpadding="20" cellspacing="0" border="1"  width="100%"
 
{| style="cellpadding="20" cellspacing="0" border="1"  width="100%"
Line 33: Line 34:
 
| pwd is a shell [[builtin command]].
 
| 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:
 +
<source lang="bash">type -p ls</source>
 +
Nothing is return as ls is aliased on my [[CentOS Linux]] system. You can verify this by typing the following command:
 +
<source lang="bash">type -t ls</source>
 +
However, the following should return full disk path to date command:
 +
<source lang="bash">type -p date</source>
 +
Sample Outputs:
 +
<pre>/bin/date</pre>

Revision as of 12:03, 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