DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Customizing your environment

Using aliases

In the context of the shells, an alias is a specially defined synonym for a command or commands. You can define aliases for complex operations, or rename commands (for example, to make life easier if you are moving to the UnixWare system from DOS).

Aliases are not available in the Bourne shell. This discussion covers the mechanisms provided by the Korn shell: the C shell also provides aliases, but the syntax differs.

Suppose you frequently need to issue the following command:

grep red | grep -v brown

This command searches a file or an input pipe for lines containing the word ``red'', then excludes lines that also contain the word ``brown''. From inside the Korn shell, you can set up an alias called prism that is an abbreviation for this pipe with the following command:

alias -x prism='grep red | grep -v brown'

When you next type the command prism, the shell will check its internal table of aliases, and replace the word prism with the value of the alias. So if you type the following:

cat foo |prism

The command that actually gets run is as follows:

cat foo | grep red | grep -v brown

The -x option to alias makes the alias remain in force for all scripts that run under the current shell session. Otherwise, the alias will not be exported to any shell scripts you run.

The syntax of alias differs under the C shell. The equivalent command to create the alias under csh is:

alias prism='grep red | grep -v brown'

If you use aliases a lot, you might want to save them in a file called .aliases, executed from your .profile or .login scripts. For example, you could add the following line to your .login file:

   . ~/.aliases
If you need aliases to be exported to scripts running under the current shell session, they should be defined using the -x option to the alias command (under the Korn shell).
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004