[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

System User's Guide: Operating System and Devices

Alias Substitution in the C Shell

An alias is a name assigned to a command or command string. The C shell allows you to assign aliases and use them as you would commands. The shell maintains a list of the aliases that you define.

After the shell scans the command line, it divides the commands into distinct words and checks the first word of each command, left to right, to see if there is an alias. If an alias is found, the shell uses the history mechanism to replace the text of the alias with the text of the command referenced by the alias. The resulting words replace the command and argument list. If no reference is made to the history list, the argument list is left unchanged.

For information about the C shell history mechanism, see History Substitution in the C Shell.

The alias and unalias built-in commands establish, display, and modify the alias list. Use the alias command in the following format:

alias [Name [WordList]] 

The optional Name variable specifies the alias for the specified name. If you specify a word list with the WordList variable, the command assigns it as the alias of the Name variable. If you run the alias command without either optional variable, it displays all C shell aliases.

If the alias for the ls command is ls -l, the following command:

ls /usr

is replaced by the command:

ls -l /usr

The argument list is undisturbed because there is no reference to the history list in the command with an alias. Similarly, if the alias for the lookup command is as follows:

grep \!^ /etc/passwd

then the shell replaces lookup bill with the following:

grep bill /etc/passwd

In this example, !^ refers to the history list, and the shell replaces it with the first argument in the input line, in this case bill.

You can use special pattern-matching characters in an alias. The following command:

alias lprint 'pr &bslash2.!* >
> print'

creates a command that formats its arguments to the line printer. The ! character is protected from the shell in the alias by use of single quotation marks so that the alias is not expanded until the pr command runs.

If the shell locates an alias, it performs the word transformation of the input text and begins the alias process again on the reformed input line. If the first word of the next text is the same as the old, looping is prevented by flagging the alias to terminate the alias process. Other subsequent loops are detected and result in an error.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]