alias — Display or create a command alias

Format

For the tcsh shell:
  • alias [name [wordlist ]]

Description

When the first word of a shell command line is not a shell keyword, alias causes the shell to check for the word in the list of currently defined aliases. If it finds a match, the shell replaces the alias with its associated string value. The result is a new command line that might begin with a shell function name, a built-in command, an external command, or another alias.

When the shell performs alias substitution, it checks to see if value ends with a blank. If so, the shell also checks the next word of the command line for aliases. The shell then checks the new command line for aliases and expands them, following these same rules. This process continues until there are no aliases left on the command line, or recursion occurs in the expansion of aliases.

Calling alias without parameters displays all the currently defined aliases and their associated values. Values appear with appropriate quoting so that they are suitable for reinput to the shell.

Calling alias with parameters of the form name=value creates an alias for each name with the string value.

If you are defining an alias where value contains a backslash character, you must precede it with another backslash. The shell interprets the backslash as the escape character when it performs the expansion. If you use double quotation marks to enclose value, you must precede each of the two back slashes with an additional backslash, because the shell escapes characters—that is, the shell does not interpret the character as it normally does—both when assigning the alias and again when expanding it.

To avoid using four back slashes to represent a single backslash, use single quotation marks rather than double quotation marks to enclose value, because the shell does not escape characters enclosed in single quotation marks during assignment. As a result, the shell escapes characters in single quotation marks only when expanding the alias.

Calling alias with name without any value assignment displays the function name (name) and its associated string value (value) with appropriate quoting.

DBCS recommendation: Use single-byte characters when specifying an alias name, because the POSIX standard states that alias names must contain only characters in the POSIX portable character set.

In the tcsh shell:
  • Without arguments, alias in the tcsh shell prints all aliases.
  • With name, alias prints the alias for name. With name and wordlist, alias assigns wordlist as the alias of name. wordlist is command and filename substituted. name cannot be alias or unalias.

See also the information about unalias in the tcsh shell in unalias — Remove alias definitions.

Options

–r
Removes all tracked aliases.
–t
Makes each name on the command line a tracked alias. Each tracked alias resolves to its full path name; the shell thus avoids searching the PATH directories whenever you run the command. The shell assigns the full path name of a tracked alias to the alias the first time you invoke it; the shell reassigns a path name the first time you use the alias after changing the PATH variable.
When you enter the command:
set –h
each subsequent command you use in the shell automatically becomes a tracked alias. Running alias with the –t option, but without any specified names, displays all currently defined tracked aliases with appropriate quoting.
–x
Marks each alias name on the command line for export. If you specify –x without any names on the command line, alias displays all exported aliases. Only exported aliases are passed to a shell that runs a shell script.
Several aliases are built into the shell. Some of them are:
alias autoload="typeset –fu"
alias functions="typeset –f"
alias hash="alias –t"
alias history="fc –l"
alias integer="typeset –i"
alias nohup="nohup "
alias r="fc –s"
alias stop="kill –STOP"
alias suspend="stop \$\$"

You can change or remove any of these aliases. These changes remain in effect for the current shell and any shell scripts or child shells invoked implicitly from the command. These aliases are reset to their default built-in values each time a new shell is invoked from the command line.

Examples

  1. The command:
    alias ls="ls –C"
    defines ls as an alias. From this point on, when you issue an ls command, it produces multicolumn output by default.
  2. For the tcsh shell, to alias the !! history command, use \!-1 instead of \!\!. For example:
    alias mf 'more \!-1$'
    creates an alias for looking at the file named by the final argument of the previously entered command. Example output would be the following:
    alias mf 'more \!-1$'
    echo "We love tcsh." > file1
    mf
    
    
    We love tcsh.
    "file1" (EOF)
    where mf pulls the last argument of the previous command (file1), and then displays that file using the more command.

Localization

alias uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Usage notes

  1. alias is a built-in shell command.
  2. Because exported aliases are only available in the current shell environment and to the child processes of this environment, they are not available to any new shell environments that are started (via the exec sh command, for example). To make an alias available to all shell environments, define it as a nonexported alias in the ENV file, which is executed whenever a new shell is run.

Exit values

0
Successful completion
1
Failure because an alias could not be set
2
Failure because of an incorrect command-line option

If you define alias to determine the values of a set of names, the exit value is the number of those names that are not currently defined as aliases.

Portability

POSIX.2 User Portability Extension, UNIX KornShell.

The –t and –x options are extensions to the POSIXstandard.

Related information

fc, hash, nohup, set, sh, typeset, unalias, tcsh