-->
Previous | Table of Contents | Next |
Command aliases are commands that you can specify and execute. Alias commands are usually abbreviations of other Linux commands. You tell tcsh to execute a Linux command whenever it encounters the alias. For example, if you enter the following alias command:
alias ls ls -F
the ls -F command is substituted for the ls command each time the ls command is used.
If you decide after you enter an alias that you dont need or want that alias to exist any longer, you can use the tcsh unalias command to delete that alias:
unalias cd
After you use the unalias command to remove an alias, the alias no longer exists, and trying to execute that alias causes tcsh to return a command not found error message.
Some aliases that you may want to define are:
If you are a DOS user and are accustomed to using DOS file commands, you may also want to define the following aliases:
Note:
When you define aliases, quotation marks are necessary only if the command within them contains spaces or other special characters.
If you enter the alias command without any arguments, it prints to the screen all of the aliases that are already defined. The following listing illustrates sample output from the alias command:
alias ls ls -F alias dir ls alias ll ls -l alias md mkdir alias rd rmdir
The standard input and output of a command can be redirected using the same syntax that is used by bash and pdksh. The < character is used for input redirection, and the > character is used for output redirection. The following command redirects the standard input of the cat command to the .cshrc file:
cat < .cshrc
In practice, input redirection isnt used very often because most commands that require input from a file support passing the filename as an argument to the command.
Output redirection is used much more frequently. The following command redirects the standard output of the cat command to the file named cshenv (which has the effect of storing the contents of the .cshrc and .login files in one file named cshenv):
cat .cshrc .login > cshenv
Caution:
The file to which output is being redirected is created if it does not exist and is overwritten without warning if it already exists.
tcsh pipelines, just like bash and pdksh pipelines, are a way to string together a series of Linux commands. This means that the output from the first command in the pipeline is used as the input to the second command in the pipeline. The output from the second command in the pipeline is used as input to the third command in the pipeline, and so on. The output from the last command in the pipeline is the output that the user actually sees. This output is displayed to the screen (or put into a file if output redirection was specified on the command line).
You can tell tcsh to create a pipeline by typing two or more commands separated by the | character. The following command illustrates an example of using a tcsh pipeline:
cat file1 file2 | wc -l
The cat command in this pipeline appends file2 to the end of file1 and passes the resulting file to the wc command. The wc command prints to the screen the total number of lines contained in the resulting file.
tcsh has three levels of user prompts. The first-level prompt is what you see when tcsh is waiting for you to type a command. The default prompt is the % character. This prompt can be customized by assigning a new value to the prompt tcsh variable:
set prompt=%t$
This example changes the first-level prompt to the current time followed by a dollar sign.
The second-level prompt is displayed when tcsh is waiting for input when in a while or for loop (used in shell programming, discussed in Chapter 14, Shell Programming). The default for the second-level prompt is %R?, where %R is a special character sequence that displays the status of the parser. You can change the second-level prompt by setting the value of the prompt2 tcsh variable. For example:
set prompt2=?
changes the second-level prompt to a question mark.
The third-level prompt is used when tcsh displays the corrected command line when automatic spelling correction is in effect. This prompt is set using the prompt3 variable, and it has a default value of CORRECT>%R (y|n|e)?. See the Correcting Spelling Errors section that appears later in this chapter for more information on this feature.
tcsh supports special character codes in its prompt variables. These codes are similar to the codes that bash supports in its prompts. The main difference between the two is that the syntax for using them is different. Table 13.1 lists the most commonly used special character codes.Character code | Meaning |
---|---|
%/ | Displays the current working directory. |
%h, %!, ! | These codes all display the current history number. |
%t, %@ | These codes both display the time of day. |
%n | Displays the username. |
%d | Displays the current day of the week. |
%w | Displays the current month. |
%y | Displays the current year. |
The following is an example of setting the prompt variable:
set prompt=%h %/
This command sets the prompt to display the history number of the current command, followed by the current working directory.
Previous | Table of Contents | Next |