Examples of creating command aliases in the TC shell

To create a simple command alias:

   alias del 'rm -i'
   del memo.txt
   rm: remove memo.txt? y

This creates the alias del for the command rm -i which prompts you for confirmation that you want to remove a file before it does so.

Make this alias a permanent feature of your environment by adding it to your shell start up file .tcshrc.


To create a command alias that consists of several commands:

   alias what 'ps -aux | grep $USER | less'

This creates the alias what.

Entering the command what will now run the command

   ps -aux | grep $USER | less

which consists of three commands linked together with pipes.


To refer to another command alias within an alias:

   alias h history
   alias rev  'h | tail -10'

The first command assigns the alias h to the history command. The next command assigns the alias rev to the command h | tail -10. This takes the output from the alias h ( the history command) and pipes it through the tail command to list the ten most recent commands in the command history.


To pass command arguments to the alias:

   alias print 'lpr \\!^ -Pps5'

To print a file to the printer ps5 the user enters a command such as:

   print memo.txt

The notation !^ causes the first argument to the command alias print to be inserted in the command at this point. The command that is carried out is:

   lpr memo.txt -Pps5

Notice that the ! character is preceded by a \\ to prevent it being interpreted by the shell as a history command.


[Home] [Search] [Index] This site maintained by bondaren@thsun1.jinr.ru