Main index

Introducing UNIX and Linux


Advanced shell programming

Overview
Sending and trapping signals
      Signal names
Functions
Aliases
The 'exec' mechanism
The 'eval' mechanism
Sending data across networks
      Sending printable characters
      Splitting files
Makefiles
Safe programming
Setting up a terminal
More on files
Miscellaneous utilities
Summary
Exercises

Aliases

Functions are general-purpose, and can be arbitrarily long. A mechanism similar to functions, but suitable for naming short commands only, is that of aliasing. The format is

alias alias-name=string

and whenever the alias-name is encountered it is replaced by the string, whose value is then executed as a command. For instance, instead of naming ll above using functions, we could have

alias ll='ls -l'

The command alias, with no arguments, lists all the aliases you have set up, and alias followed by a name (assumed to be the name of an alias) will display the string that alias represents. To remove an alias definition, the command unalias can be used.

When the shell encounters a name, it first of all checks to see whether it is an alias; if not, the shell sees if there is a function definition for it. If both of these fail, it examines the PATH to find an executable command by that name.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck