An alias is a name assigned to a command or command string. The C shell allows you to assign aliases and use them just as you would commands. The shell maintains a list of the aliases you define.
After the shell scans the command line, it divides it into distinct words and checks the first word of each command, left to right, to see if it has an alias. If it does, 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 issue the alias command without either optional variable, it displays all C shell aliases.
If the alias for the ls command is ls -l , the command:
ls /usr
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:
grep \!^ /etc/passwd
then the shell replaces lookup bill with:
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 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 quotes so that it 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 it to terminate the alias process. Other subsequent loops are detected and result in an error.