The Korn shell, or POSIX shell, allows you to create aliases to customize commands. The alias command defines a word of the form Name=String as an alias. When you use an alias as the first word of a command line, ksh checks to see if it is already processing an alias with the same name. If it is, ksh does not replace the alias name. If an alias with the same name is not already being processed, ksh replaces the alias name by the value of the alias.
The first character of an alias name can be any printable character, except the metacharacters. The remaining characters must be the same as for a valid identifier. The replacement string can contain any valid shell text, including the metacharacters.
If the last character of the alias value is a blank, the shell also checks the word following the alias for alias substitution. You can use aliases to redefine special built-in commands, but not to redefine reserved words. Alias definitions are not inherited across invocations of ksh. However, if you specify alias -x, the alias stays in effect for scripts invoked by name, that do not invoke a separate shell. To export an alias definition and to cause child processes to have access to them, you must specify the alias -x as well as the alias definition in your environment file.
To create, list, and export aliases, use the alias command. Remove aliases with the unalias command.
The format for creating an alias is:
in which the Name parameter specifies the name of the alias and the String parameter specifies the value of the alias.
The following exported aliases are predefined by the Korn shell, but can be unset or redefined. We recommend that you do not change them, because this might later confuse anyone who expects the alias to work as predefined by ksh.
autoload='typeset -fu' false='let 0' functions='typeset -f' hash='alias -t' history='fc -l' integer='typeset -i' nohup='nohup ' r='fc -e -' true=':' type='whence -v'
Aliases are not supported on noninteractive invocations of the Korn shell (ksh); for example, in a shell script, or with the -c option in ksh, as in:
ksh -c alias
For more information about aliasing, see Creating a Command Alias (Creating a Command Alias (alias Shell Command)) and the alias command in the AIX 5L Version 5.1 Commands Reference.
Frequently, aliases are used as shorthand for full path names. One aliasing facility option allows you to automatically set the value of an alias to the full path name of a corresponding command. This special type of alias is a tracked alias. Tracked aliases speed execution by eliminating the need for the shell to search the PATH variable for a full path name.
The set -h command turns on command tracking so that each time a command is referenced, the shell defines the value of a tracked alias. This value is undefined each time you reset the PATH variable.
These aliases remain tracked so that the next subsequent reference will redefine the value. Several tracked aliases are compiled into the shell.
After the shell performs alias substitution, it checks each word to see if it begins with an unquoted tilde (~). If it does, the shell checks the word, up to the first slash (/), to see if it matches a user name in the /etc/passwd file. If the shell finds a match, it replaces the ~ character and the name with the login directory of the matched user. This process is called tilde substitution.
The shell does not change the
original text if it does not find a match. The Korn shell also makes
special replacements if the ~ character is the only character in the word or
followed by plus sign (+) or hyphen (-):
|~||Replaced by the value of the HOME variable.|
|~+||Replaced by the $PWD variable (the full path name of the current directory).|
|~-||Replaced by the $OLDPWD variable (the full path name of the previous directory).|
In addition, the shell attempts tilde substitution when the value of a variable assignment parameter begins with a tilde ~ character.