next up previous contents
Next: Environment variables (setenv, printenv) Up: The Shell (csh, tcsh, Previous: The Shell (csh, tcsh,   Contents

Creating aliases (alias)

One command found throughout the ``.cshrc'' file is alias. Use the alias command to create aliases for long, complicated commands, or to set up a command so that it will always use certain useful qualifiers. Aliases are analogous to VMS symbols. The format for an alias is:

alias symbol command , e.g.

malama% alias dir ls -asF

This alias sets the word ``dir'' to be the command ls -asF. You can alias a command to itself, which has the advantage that you keep using generic UNIX command names. The disadvantage is also precisely that: you may become accustomed to a non-standard behaviour of a command which can get you in real troubles in case you happen to be working on some other unix host. In addition scripts may show unexpected behaviour becuase they were written for the generic command. Hence, instead of aliasing rm, mv, and cp to there `-i' equivalents, you may want to call those versions e.g. del, move, and copy.

You can also create aliases that perform several commands in succession by using the command-separation symbol ``;''. If your alias is set to more than one command put the commands inside single quotes, e.g.:

malama% alias cd '$\backslash$cd $\backslash$!*; pwd'

This alias will set your default to whatever you specify when you use cd, and then print the name of the new directory. Note the ``$\backslash$'' in front of the ``cd'' in the definition; this is to prevent retranslation of the cd alias while the command is actually executing, since you want the real function of the cd command there. You can use this directly, should you wish to get the normal behavior of a command instead of the way you have aliased it.

Typing alias by itself, or with just an alias name and no value, will display the meaning of either all your aliases, or just the one you specified.

A similar function is available in the Korn shell, but is defined completely differently. In your .profile file, the definition of the alias dir shown above would look like:

dir() { ls -asF $* ;}


next up previous contents
Next: Environment variables (setenv, printenv) Up: The Shell (csh, tcsh, Previous: The Shell (csh, tcsh,   Contents
h.stilmack@jach.hawaii.edu