Previous Table of Contents Next


Module 156
whence (ksh)/type (sh)

DESCRIPTION

The internal whence command displays how the shell would interpret the given arguments as commands. For example, if you want to know where the cat command is being executed from, you type whence cat and press Return. The whence command is similar to the Bourne shells type command. There are three basic types of commands described by whence; they are:

*  aliases - the value of an alias is displayed
*  internals - the command name is displayed
*  externals - the PATH is searched and the full path is displayed

COMMAND FORMAT

Following is the general format of the whence command.

    whence [ -v> ] [ command ... ]

Options

The only option whence recognizes is:

-v Verbose information. The -v causes whence to display a more verbose description of each command listed as an argument.

Arguments

The only arguments whence can use are commands that exist on the system or in the shell.

command Any command that is an alias, internal, or external command.

FURTHER DISCUSSION

For more detailed information about how the command is interpreted you can use the -v option. An example of the three types of commands and the -v option follow to clarify the use of whence:

    cj> whence -v ls
    ls is /bin/ls

    cj> whence pwd
    print - $PWD

    cj> whence -v pwd
    pwd is an exported alias for print - $PWD

    cj> whence exit
    exit is a built-in command

The Bourne shell's type command is not as smart or complex as the whence command. It does not have the -v option nor does it know about aliases since the Bourne shell does not support them. The type command is implemented in the Korn shell as an alias:

    alias type="whence -v"

that uses the Korn shell's whence command.

RELATED COMMANDS

Refer to the which command described in Module 158 for an equivalent command used on BSD Systems.

RELATED FILES

The whence and type commands write to the standard output.

APPLICATIONS

The whence command is used to find the location or source of a command. whence is helpful in finding were certain commands are located. By knowing command locations you can rearrange your PATH directories for more efficient command searches. You can assign new aliases to override the default location of the command, thereby creating your own version of an existing command. Many people just want to know were a command resides.

On some of the multiversion UNIX systems running System V and Berkeley 4.3 whence can be used to locate where a command is being found by the shell. For example, on a Sun workstation the Berkeley echo command is in /bin/echo, while the System V echo is stored in /usr/5bin/echo. The whence command would allow you to know which echo command your PATH points to first (which echo command is executed).

TYPICAL OPERATION

In this activity you use the whence command to locate diffent types of commands. If you are not using the ksh skip to the next module. Although some versions of the csh have incorporated this command, so you might try it if you're using the csh. Begin at the shell prompt.

1.  Type whence cat and press Return. Notice the returned message:
    cj> whence cat
    /bin/cat

This shows the cat command resides in the /bin directory.
2.  Type whence -v cat and press Return to display more information about the cat command. Notice the more verbose output:
    cj> whence -v cat
    cat is /bin/cat

or
    cat is a tracked alias for /bin/cat
3.  Turn to Module 148 (SV), Module 158 (BSD) to continue the learning sequence.


Previous Table of Contents Next