It can clearly be seen that filename substitutions can be used to
refer to files which are long to type or possibly off the screen and
thus difficult to refer to.
For example, a directory might contain several hundred files (take a
look at /usr/bin) and a user might want to examine a data file that he
can only remember starts with the month it was created, say june.
Well he could pipe the listing to the more command like:
ls -l | more
which would allow the user to examine all of the files a page at a time, or he could try:
head june*
which would display the first few lines of each file starting with
june, thus allowing the user to examine the files and find which one
he wants to look closer at.
There are many ways to handle the problem using various commands and
filename substitions, but the C shell provides an even better method,
command completion.
If the variable filec is set (refer to the section on
variables) using the command set filec, a filename can be
completed at any time during command line input using the ESC-key.
For example, if there is a subdirectory called
all_of_my_data_files in the current directory, the user could
type the following:
cd al[ESC]
at which point the rest of the name would be filled in by the shell.
This is of course only true if the rest of the filename is unique.
If it is not, the shell will beep alerting the user that the
completion is ambiguous.
This would occur if there were three files in the current directory
starting with ``th'', and the user tried filename completion after
entering just a ``t''.
One way to fix this problem is to enter the EOF (end-of-file) key
combination (usually Control-D, often written ^D) rather than
the escape key, at which point a list of choices will be displayed by
the shell.
The following session illustrates the above (the text following the
hash marks are comments only, for purpose of clarity):
% ls Mail/ News/ data_june95/ data_march95/ data_may95/ cleanup* % cd d[ESC] # system beep sounds % cd data_ # actually the same line as above % cd data_[^D] # still the same line as above data_june95 data_march95 data_may95 % cd data_j[ESC] % pwd /home/jblow/data_june95
This may look a bit confusing, but with a bit of practice, it will become an invaluable tool. The example above illustrates how the shell will complete as much of the command as it can before ambiguity sets in. This will allow command completion at any point of the desired filename so that the user will not have to enter input to the point of unique characters before using completion.