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.
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.
ls /usr
is
replaced by the command:ls -l /usr
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
.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 previous text, then looping is prevented by flagging the alias to terminate the alias process. Other subsequent loops are detected and result in an error.