Linux Unleashed, Third Edition:tcsh3
-->
Previous
Table of Contents
Next
Correcting Spelling Errors
This feature, which is not available with any of the other shells discussed in this book, is a dream come true for many people (including me). If youre plagued by recurring typos, this feature alone might cause you to use tcsh over any of the other shells. You can tell tcsh to correct spelling errors in a command that you entered, and you can also tell it to automatically try to correct commands that it cant figure out.
The first function isnt quite as useful because you must know that you have made a typing mistake before you actually execute the command. This feature is invoked by pressing Esc+S on the command line before you press Enter.
For example, suppose you want to change to the /usr/X386/X11/bin directory, so you type the following command on the command line:
cd /usr/X387/X11/bun
If you caught the typing errors before you executed the command (by pressing the Enter key), you can correct the errors by pressing Esc+S. tcsh then tries to correct the spelling of the command and changes the command to read
cd /usr/X386/X11/bin
You can now press the Enter key, and the command executes just as you wanted. Obviously this command has some limitations because the shell cant (yet) read your mind, but for simple character transpositions or capitalization errors, it works very nicely.
The second method of instructing tcsh to perform spelling corrections on your commands is to set the correct tcsh variable. This variable, depending on what options you use, tells tcsh to try to correct spelling errors in command names or anywhere in the command. The syntax for setting the correct variable is one of the following:
set correct=cmd or
set correct=all
After you set the correct variable, whenever you enter a command that tcsh doesnt understand, it automatically checks to see if the command has any spelling errors. If it finds possible spelling errors, it gives you the corrected command and asks if the new command is what you intended. For example, if you set the correct variable with the all option and then enter the following command:
cd /usr/gmes
tcsh would respond with the following prompt on the command line:
CORRECT>cd /usr/games (y|n|e)?
If you respond to the prompt by pressing the y (yes) key, tcsh executes the corrected command. If you respond to the prompt by pressing the n (no) key, tcsh executes the command that you initially entered, which in turn causes an error message to be displayed.
If you respond to the prompt by pressing the e (edit) key, tcsh puts the command that you entered back on the command line and enables you to edit it.
Precommands
tcsh supports a way of executing a command prior to displaying each command prompt. This is done through the use of a special variable called precmd. If the precmd variable is set, the command that it is set to is executed before the command prompt is displayed onscreen. For example, assume that you set the precmd variable using the following command:
alias precmd time
After this alias is declared, the time command is always executed before the command prompt is displayed onscreen.
Change Directory Commands
tcsh also supports change directory commands. These commands are executed only when the current directory changes (usually as a result of executing the cd command). This type of command is probably more useful than the precommands just mentioned because there are times when you may want to know something about a directory that you just entered.
This feature is supported in the same way precommands are supported, except that you must provide an alias for a different variable. The variable used for this is cwdcmd. If this variable is aliased to a command, that command is executed each time you change current working directories.
A common use for this variable is to display the current directory to the screen. This can be done by entering the command
alias cwdcmd pwd
Warning: You should not put a cd command into cwdcmd. Doing so could cause an infinite loop that will cause you to lose control of tcsh.
This displays the name of the new directory each time a new directory is entered.
Monitoring Logins and Logouts
tcsh provides a mechanism that enables you to watch for any user who logs on or off the system. It does this through a tcsh variable named watch.
The watch variable contains a set of user ID and terminal number pairs. These pairs can contain wildcards and also can contain the word any, which tells tcsh to match any user or terminal. The syntax for setting the watch variable is
set watch=(<user> <terminal>)
The user in this command refers to a Linux user ID. terminal refers to a Linux terminal device number.
Most people use this capability to watch for friends logging on to the system. For example, if you were waiting for a person with the username jules to come to work in the morning, you could set the following watch variable:
set watch=(jules any)
This command will then inform you when a person with the user ID jules logged in to the system on any terminal. tcsh defaults to checking the defined watches every 10 minutes. If you want to know with greater or lesser frequency, you can change this default by passing the number of minutes to wait between checks as the first parameter to the watch variable. For example, to check every five minutes to see if jules has logged in, you would use the following watch variable:
set watch=(5 jules any)
This does the same thing as the first command, except that it checks every 5 minutes instead of every 10 to see if jules has logged in. Be careful using this type of command on a heavily loaded or slow Linux system as youre contributing to the load. If youre using these commands for a short period of time for a particular purpose, thats fine, but dont let them run nonstop or youll be loading the system for no good reason.
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
254 257254 257254 255demo cgi 254257 259254 25626 (257)257 313 (2)254 (2)więcej podobnych podstron