-->
Previous | Table of Contents | Next |
by Rick McMullin
The last two chapters introduced you to the Bourne Again Shell (bash) and the Public Domain Korn Shell (pdksh). This chapter introduces a third shell, tcsh. In addition to these topics, we will see how you can customize tcsh to suit your tastes. You will also be introduced to several important tcsh commands and variables.
Rounding out the chapter is a section on several neat little features that tcsh provides that are not available in any of the other shell programs we have discussed.
tcsh is a modified version of the C shell (csh). It is fully backward-compatible with csh, but it contains many new features that make user interaction much easier. The biggest improvements over the csh are in the areas of command-line editing and history navi-gation.
Just like pdksh and bash, tcsh supports command-line completion. You invoke command-line completion in tcsh exactly the same way that you do in bash: by pressing the Tab key at any point while you type a command.
When you press the Tab key, tcsh tries to complete the command by matching what has been typed with any file in the directory that the command is referring to. For example, lets say that you type the following command and then press the Tab key:
emacs hello
Here, tcsh tries to match the letters hello with any file (or subdirectory) in the current directory. If there is a single file in the current directory that begins with the letters hello, tcsh fills in the rest of the filename for you. Now lets see what happens when you type the following command and then press the Tab key:
emacs /usr/bin/hello
In this case, tcsh will try to match the letters hello with any file in the /usr/bin directory. From these examples, you can see that you must give tcsh something to go on before asking it to complete the command for you.
Another example of using command-line completion is as follows: Assume that the directory that you are currently in contains these files:
News/ bin/ mail/ sample.txt testfile ttd.txt
If you want to print the sample.txt file, type the following command:
lpr sample.txt
Using command-line completion, you can get away with typing the following command and then pressing the Tab key:
lpr s
At this point, tcsh attempts to complete the command and finds that the only file that can possibly match what was typed so far is the sample.txt file. tcsh then completes the command by putting the following text on the command line:
lpr sample.txt
You can now either confirm that this is the intended command by pressing the Enter key, or you can edit the command if it isnt the one that you want. Be careful using these shortcuts with some commands, notably rm, as you may end up deleting more files than you intended!
tcsh enables you to use wildcards in your commands. It supports the same three wildcards as bash and pdksh:
The * wildcard can be used to perform some of the same functions as command-line completion. If you enter a command like
cd t*
and only one subdirectory in the current directory begins with the letter t, this command behaves the same as if you had used command-line completion by pressing the Tab key.
The * matches any character or any number of characters, so the shell replaces the t* with the file in the directory that matches the wildcard pattern.
This works reliably only if there is one file in the directory that starts with the letter t. If more than one file in the directory starts with the letter t, the shell tries to replace t* with the list of filenames in the directory that match the wildcard pattern, and the cd command makes the first directory in this list the working directory. This ends up being the file that comes first alphabetically and may or may not be the intended file.
A case that is more suited to using the * wildcard is if you want to perform the same operation on a number of files that have similar filenames. For example, assume the current directory contains the following files:
Mail/ atc1.stk atc2.stk bin/ borl.stk cdrom.txt lfi.stk temp/
If you want to print both of the files that start with atc and end with the .stk extension, you can do so by typing
lpr a*.stk
This command will do the job because there are no other files in the directory that start with the letter a and have the .stk extension.
Using the ? wildcard, the following command accomplishes the same thing:
lpr atc?.stk
Using the [ ] wildcard, you can enter the following command to get the same files to print:
lpr atc[12].stk
Previous | Table of Contents | Next |