|
-
For example, to create a simple command alias, first open your
.tcshrc file in your home directory using any text editor of
your choice. (if you do not have a .tcshrc file in your
home directory, then open .cshrc and add aliases)
-
alias del 'rm -i'
This creates an alias del for the command
"rm -i" which prompts you for confirmation that you want to remove a
file before it does so.
To create a command alias that consists of a series of commands,
-
alias ll '/usr/bin/ls -Flsa |more'
This creates an alias ll for the command
"ls" with "Flsa" flags and pipe the result to "more" command to
display the result one screenful at a time.
Of course, you can refer to another command alias within an alias,
-
alias h history
alias rev 'h | tail -10'
The first command assigns an alias h to the
"history" command. The next
command assigns another 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.
Here an example to pass command arguments to the alias,
-
alias print 'lpr \\!^ -Php4'
Now, to print a file to the CEE UCL default printer "hp4,"
you can enters a command such as:
-
$ print ohboy.f
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 ohboy.f -Php4
Of course, you can also pass multiple arguments to a command alias.
-
alias mprint 'lpr \\!* -Php4'
The notation "!*" causes multiple arguments given to the alias
mprint to be inserted in
the command. If you enters following command
-
$ mprint ohboy.f headache.txt huge_bug_list.ps
the actual command would look like
-
lpr ohboy.f headache.txt huge_bug_list.ps -Php4
Notice that the "!" character is preceeded by a
"\\" to prevent it being interpreted by Tc shell as a metacharacter.
The reason is that "!" is one of shell metacharacters
that are inetrpreted as something other than the character or symbol
by the shell. FYI, here's a list of all metacharacters for Tc shell.
- ; & ( ) | ^ < > ~ % { }
- $ # ' " \ @@ * ? [ ] - !
- Newline (a <Return>)
- Space (a <Space>)
- Tab (a <Tab>)
|