📄 254-257.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:tcsh3</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=13//-->
<!--PAGES=254-257//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="252-254.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="257-260.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Correcting Spelling Errors</FONT></H4>
<P>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 you’re plagued by recurring typos, this feature alone might cause you to use <TT>tcsh</TT> over any of the other shells. You can tell <TT>tcsh</TT> to correct spelling errors in a command that you entered, and you can also tell it to automatically try to correct commands that it can’t figure out.</P>
<P>The first function isn’t 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 <TT>Esc+S</TT> on the command line before you press Enter.</P>
<P>For example, suppose you want to change to the <TT>/usr/X386/X11/bin</TT> directory, so you type the following command on the command line:</P>
<!-- CODE SNIP //-->
<PRE>
cd /usr/X387/X11/bun
</PRE>
<!-- END CODE SNIP //-->
<P>If you caught the typing errors before you executed the command (by pressing the Enter key), you can correct the errors by pressing <TT>Esc+S</TT>. <TT>tcsh</TT> then tries to correct the spelling of the command and changes the command to read</P>
<!-- CODE SNIP //-->
<PRE>
cd /usr/X386/X11/bin
</PRE>
<!-- END CODE SNIP //-->
<P>You can now press the Enter key, and the command executes just as you wanted. Obviously this command has some limitations because the shell can’t (yet) read your mind, but for simple character transpositions or capitalization errors, it works very nicely.
</P>
<P>The second method of instructing <TT>tcsh</TT> to perform spelling corrections on your commands is to set the correct <TT>tcsh</TT> variable. This variable, depending on what options you use, tells <TT>tcsh</TT> 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:</P>
<!-- CODE SNIP //-->
<PRE>
set correct=cmd or
set correct=all
</PRE>
<!-- END CODE SNIP //-->
<P>After you set the correct variable, whenever you enter a command that <TT>tcsh</TT> doesn’t 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 <TT>all</TT> option and then enter the following command:</P>
<!-- CODE SNIP //-->
<PRE>
cd /usr/gmes
</PRE>
<!-- END CODE SNIP //-->
<P><TT>tcsh</TT> would respond with the following prompt on the command line:</P>
<!-- CODE SNIP //-->
<PRE>
CORRECT>cd /usr/games (y|n|e)?
</PRE>
<!-- END CODE SNIP //-->
<P>If you respond to the prompt by pressing the y (yes) key, <TT>tcsh</TT> executes the corrected command. If you respond to the prompt by pressing the n (no) key, <TT>tcsh</TT> executes the command that you initially entered, which in turn causes an error message to be displayed.</P>
<P>If you respond to the prompt by pressing the e (edit) key, <TT>tcsh</TT> puts the command that you entered back on the command line and enables you to edit it.</P>
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">Precommands</FONT></H4>
<P><TT>tcsh</TT> supports a way of executing a command prior to displaying each command prompt. This is done through the use of a special variable called <TT>precmd</TT>. If the <TT>precmd</TT> 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 <TT>precmd</TT> variable using the following command:</P>
<!-- CODE SNIP //-->
<PRE>
alias precmd time
</PRE>
<!-- END CODE SNIP //-->
<P>After this alias is declared, the <TT>time</TT> command is always executed before the command prompt is displayed onscreen.</P>
<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Change Directory Commands</FONT></H4>
<P><TT>tcsh</TT> also supports change directory commands. These commands are executed only when the current directory changes (usually as a result of executing the <TT>cd</TT> 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.</P>
<P>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 <TT>cwdcmd</TT>. If this variable is aliased to a command, that command is executed each time you change current working directories.</P>
<P>A common use for this variable is to display the current directory to the screen. This can be done by entering the command</P>
<!-- CODE SNIP //-->
<PRE>
alias cwdcmd ’pwd’
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Warning: </B><BR>You should not put a <TT>cd</TT> command into <TT>cwdcmd</TT>. Doing so could cause an infinite loop that will cause you to lose control of <TT>tcsh</TT>.<HR></FONT>
</BLOCKQUOTE>
<P>This displays the name of the new directory each time a new directory is entered.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">Monitoring Logins and Logouts</FONT></H4>
<P><TT>tcsh</TT> provides a mechanism that enables you to watch for any user who logs on or off the system. It does this through a <TT>tcsh</TT> variable named <TT>watch</TT>.</P>
<P>The <TT>watch</TT> 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 <TT>tcsh</TT> to match any user or terminal. The syntax for setting the <TT>watch</TT> variable is</P>
<!-- CODE SNIP //-->
<PRE>
set watch=(<<I>user</I>> <<I>terminal</I>>)
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>user</I> in this command refers to a Linux user ID. <I>terminal</I> refers to a Linux terminal device number.</P>
<P>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 <TT>jules</TT> to come to work in the morning, you could set the following <TT>watch</TT> variable:</P>
<!-- CODE SNIP //-->
<PRE>
set watch=(jules any)
</PRE>
<!-- END CODE SNIP //-->
<P>This command will then inform you when a person with the user ID <TT>jules</TT> logged in to the system on any terminal. <TT>tcsh</TT> 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 <TT>watch</TT> variable. For example, to check every five minutes to see if “jules” has logged in, you would use the following <TT>watch</TT> variable:</P>
<!-- CODE SNIP //-->
<PRE>
set watch=(5 jules any)
</PRE>
<!-- END CODE SNIP //-->
<P>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 you’re contributing to the load. If you’re using these commands for a short period of time for a particular purpose, that’s fine, but don’t let them run nonstop or you’ll be loading the system for no good reason.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="252-254.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="257-260.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -