tcsh lets you set command aliases.
You can use aliases to:
- People who frequently mistype mroe when they actually mean more might set:
% alias mroe more
- People more familiar with Microsoft Windows commands than UNIX commands might alias dir to run ls.
- If you will be using UNIX regularly, it is usually best to not add too many other system command aliases and just learn the real UNIX commands.
- Aliases only get expanded for things in the command portion of the command line.
- alias commands themselves go in .cshrc.
- If you want command line arguments to appear inside an alias, you need to use history-like mechanisms to get them there.
- For example, if you wanted to set up an alias that would start up the editor for you appending .txt to the name of the filename you give on command line you could use
% alias vitxt 'vi \!$.txt'
- Quotes are needed around string and the backslash before "!" is necessary so that shell doesn't use it for history substitution before it uses it to indicate arguments being inserted into an alias.
- You can use \!*to indicate all command line arguments should be added to alias instead of just the last one:
% alias edit 'vi \!*'
% edit prog.c
%
- If alias does not contain history substitutions, then original command line arguments will not change after the alias is expanded.
- If alias does contain history substitutions, then alias will become new command and history substitutions will be done as if the line you typed with the alias on it was the previous command.
- Alias substitution loops until the first word of the resulting line has no alias in it.
- Shell does notice if an alias doesn't change the first word, as well as other possible loops so that "alias ls 'ls -AF'" is valid.
- There are a few special aliases that are not set by default but if you set them to something they get run at certain times.
- beepcmd gets run when the shell wants to send a beep.
- cwdcmd runs after every change of working directory (cd command).
- periodic runs periodically, you set period in seconds with shell variable tperiod.
- precmd runs just before you get a command prompt.
- For example, most often the first thing you do after using cd to change directories is do ls to see what is there so can make that the cwdcmd alias:
% ls Mail
mail.apr mail.feb mail.jan mail.mar mail.may
% cd Mail
mail.apr mail.feb mail.jan mail.mar mail.may
% cd ..
.Xauthority .newsrc .xmotd mbox
.Xdefaults .sh_history .xsession@
.cshrc .twmrc .xsession-errors
.login* .xinitrc* Mail/
%