< Day Day Up > |
11.5. AliasesAn alias is a Korn shell or user-defined abbreviation for a command. The alias name contains alphanumeric characters. Default aliases are provided by the shell and can be redefined or unset. Unlike the C shell aliases, the Korn shell does not support passing arguments. (If you need to use arguments, see "Functions" on page 639.) Aliases can be exported to subshells by storing them in the ENV file. (The commands in the ENV file are executed every time a new shell is spawned.) Starting with the 1988 version of the Korn shell, the �x option allows aliases to be exported to subshells as long as the new shell is not a separate invocation of ksh. Tracked aliases are provided by the Korn shell to speed up the time it takes the shell to search the path. Aliases can alias themselves; that is, they are recursive. 11.5.1 Listing AliasesThe alias built-in command lists all set aliases. Example 11.21.
1 $ alias
2 autoload=typeset �fu
3 false=let 0
4 functions=typeset �f
5 hash=alias �t
6 history=fc �l
7 integer=typeset �i
8 r=fc �e �
9 stop=kill �STOP
10 suspend=kill �STOP $$
11 true=:
12 type=whence �v
EXPLANATION
11.5.2 Creating AliasesThe user can create aliases in the Korn shell. An alias is a nickname for an existing command or commands. The real command(s) is substituted for the alias when the shell evaluates the command line. Example 11.22.1 $ alias cl='clear' 2 $ alias l='ls �laF' 3 $ alias ls='ls -aF' 4 $ \ls .. EXPLANATION
11.5.3 Deleting AliasesThe unalias command deletes an alias. Example 11.23.
unalias cl
EXPLANATION The alias cl is removed from the list of set aliases. 11.5.4 Tracked AliasesTo reduce the amount of time needed to do a search of the path, the Korn shell creates an alias when a command is first encountered and sets the alias equal to the full pathname of the command. This is called a tracked alias.[3]
The Korn shell has some preset tracked aliases that are defined when it is installed. To use tracked aliases, the set �o trackall command is issued; it is normally set in the ENV file. To see all tracked aliases, type alias �t. Example 11.24.$ alias �t chmod=/bin/chmod ls=/bin/ls vi=/usr/ucb/vi who=/bin/who EXPLANATION The �t option to the built-in alias command displays those commands that have been aliased via the tracking mechanism. When the user types any of these commands, the shell will not search the path, but use the alias definition to invoke the command. |
< Day Day Up > |