⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch12.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:


	<LI><TT>kill-whole-line</TT> (<TT>^U</TT>): Deletes all of the characters on the



	current line.



</UL>







<P>All of these commands are the same whether you're in <TT>emacs</TT> or <TT>vi</TT>



insert mode. <TT>tcsh</TT> supports many more editing commands than are listed here.



To see what these commands are, refer to the <TT>tcsh</TT> man page.</P>



<P>The following are examples of setting key bindings:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">bindkey ^W kill-whole-line







bindkey ^S beginning-of-line



</FONT></PRE>



<CENTER>



<H3><A NAME="Heading17<FONT COLOR="#000077">Other Neat Stuff</FONT></H3>



</CENTER>



<P><TT>tcsh</TT> supports a few neat features that none of the other shells discussed



in this book support. This section lists a few of the most useful of these extended



features.



<CENTER>



<H4><A NAME="Heading18<FONT COLOR="#000077">Correcting Spelling Errors</FONT></H4>



</CENTER>



<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 might be enough to 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 typed, and you also can 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 Esc-S on the command line before you press Enter.</P>



<P>For example, suppose you wanted to change to the <TT>/usr/X386/X11/bin</TT> directory,



so you typed the following command on the command line:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">cd /usr/X387/X11/bun



</FONT></PRE>



<P>If you caught the typing errors before you executed the command (by pressing the



Enter key), you could correct the errors by pressing Esc-S. <TT>tcsh</TT> will try



to correct the spelling of the command. It would change the command to read<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">cd /usr/X386/X11/bin



</FONT></PRE>



<P>You could now press the Enter key, and the command would execute 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, will tell <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:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">set correct=cmd  or







set correct=all



</FONT></PRE>



<P>After you set the correct variable, whenever you enter a command that <TT>tcsh</TT>



doesn't understand, it will automatically check to see if the command has any spelling



errors. If it finds possible spelling errors, it gives you the corrected command



and asks you if the new command is what you intended. For example, if you had set



the correct variable with the <TT>all</TT> option and then entered the following



command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">cd /usr/gmes



</FONT></PRE>



<P><TT>tcsh</TT> would respond with the following prompt on the command line:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">CORRECT&gt;cd /usr/games (y|n|e)?



</FONT></PRE>



<P>If you respond to the prompt by pressing the y (yes) key, <TT>tcsh</TT> will execute



the corrected command. If you respond to the prompt by pressing the n (no) key, <TT>tcsh</TT>



will execute the command that you initially entered, which in turn will cause an



error message to be displayed.</P>



<P>If you respond to the prompt by pressing the e (edit) key, <TT>tcsh</TT> will



put the command that you entered back on the command line and enable you to edit



it.



<CENTER>



<H4><A NAME="Heading19<FONT COLOR="#000077">Precommands</FONT></H4>



</CENTER>



<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 will be executed



before the command prompt is displayed on-screen. For example, assume that you set



the <TT>precmd</TT> variable using the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">alias precmd time



</FONT></PRE>



<P>After this alias has been declared, the <TT>time</TT> command will always be executed



before the command prompt is displayed on-screen.



<CENTER>



<H4><A NAME="Heading20<FONT COLOR="#000077">Change Directory Commands</FONT></H4>



</CENTER>



<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 might want to know something about a



directory that you just entered.</P>



<P>This feature is supported in the same way precommands are supported, only 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 will be 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<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">alias cwdcmd `pwd'



</FONT></PRE>



<P>This will display the name of the new directory each time a new directory is entered.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading21<FONT COLOR="#000077"><B>WARNING:</B> </FONT>You should not



	put a <TT>cd</TT> command into <TT>cwdcmd</TT>. Doing so could cause an infinite



	loop that would cause you to lose control of <TT>tcsh</TT>.



<HR>







</DL>







<CENTER>



<H4><A NAME="Heading22<FONT COLOR="#000077">Monitoring Logins and Logouts</FONT></H4>



</CENTER>



<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 &quot;any,&quot;



which tells <TT>tcsh</TT> to match any user or terminal. The syntax for setting the



<TT>watch</TT> variable is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">set watch=(&lt;user&gt; &lt;terminal&gt;)



</FONT></PRE>



<P>The user in this command refers to a Linux user ID. terminal refers to a Linux



terminal device number.</P>



<P>Most people would use this capability to watch for friends logging onto 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:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">set watch=(jules any)



</FONT></PRE>



<P>This command would inform you when a person with the user ID <TT>jules</TT> logged



into 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 <TT>jules</TT> has logged in, you would use the following <TT>watch</TT>



variable:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">set watch=(5 jules any)



</FONT></PRE>



<P>This will do the same thing as the first command, except it will check every 5



minutes instead of every 10 to see if <TT>jules</TT> has logged in.



<CENTER>



<H3><A NAME="Heading23<FONT COLOR="#000077">Customizing tcsh</FONT></H3>



</CENTER>



<P>I've discussed many ways of customizing <TT>tcsh</TT> in this chapter. If you



just enter the commands that we have discussed at the command line, the changes you



make will be lost every time you log out of the system. This section describes how



to store these changes in a file that will be executed each time you start <TT>tcsh</TT>.</P>



<P>Two initialization files are important to <TT>tcsh</TT>. The first is called the



login file. The commands in this file are executed when you first log into Linux.



The contents of the default login file are shown in Listing 12.2. Listing 12.2. Default



csh.login file.<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">if ($?prompt) then



umask 022



  set cdpath = ( /usr/spool )



  set notify



  set history = 100



    setenv OPENWINHOME /usr/openwin



    setenv MANPATH /usr/local/man:/usr/man/preformat:/usr/man:/usr/X11/man:



    &#194;/usr/openwin/man



    setenv MINICOM &quot;-c on&quot;



    setenv HOSTNAME &quot;'cat /etc/HOSTNAME'&quot;



    set path = ( $path /usr/X11/bin /usr/andrew/bin 



         &#194;$OPENWINHOME/bin /usr/games . )



endif



# I had problems with the Backspace key installed by `tset,' but you might want



# to try it anyway, instead of the `setenv term.....' below it.



# eval `tset -sQ &quot;$term&quot;`



# setenv term  linux



#if ! $?TERM setenv TERM linux



# set to &quot;linux&quot; for unknown term type:



if (&quot;$TERM&quot; == &quot;&quot;) setenv TERM linux



if (&quot;$TERM&quot; == &quot;unknown&quot; setenv TERM linux



set prompt = &quot;%m:%~%# &quot;



eval 'dircolors -t' # set up color-ls variables



alias ls `ls -F'



if ( { tty --silent } ) then &gt;&amp; /dev/null



  echo &quot;&quot;;fortune;echo &quot;&quot;



endif



</FONT></PRE>



<P>This file, <TT>csh.login</TT>, can be found in the <TT>/etc</TT> directory. If



you want to change any of the settings found in <TT>csh.login</TT>, you should copy



it to your home directory, rename it <TT>.login,</TT> and make the changes you want



there.</P>



<P>The other file that <TT>tcsh</TT> makes use of is <TT>cshrc</TT>. The commands



in this file are executed each time a copy of the <TT>tcsh</TT> program is run. Examples



of the types of commands that usually appear in this file are aliases and variable



declarations. This file, <TT>csh.cshrc</TT>, is also contained in the <TT>/etc</TT>



directory. If you want to make changes to this file, you should copy it to your home



directory, rename it <TT>cshrc</TT>, and make your changes there.</P>



<P>When you first log in to Linux, <TT>tcsh</TT> executes the <TT>/etc/csh.cshrc</TT>



file, followed by the <TT>/etc/csh.login</TT> file. It then checks your home directory



to see if you have a personal copy of the <TT>csh.cshrc</TT> file. This file can



be named either <TT>.tcshrc</TT> or <TT>.cshrc</TT>. If you have one of these files



in your home directory, <TT>tcsh</TT> will execute it next.</P>



<P><TT>tcsh</TT> next checks to see if you have your own copy of the <TT>csh.login</TT>



file in your home directory. This file must be named <TT>.login</TT>. If you do have



a <TT>.login</TT> file in your home directory, it will be executed next.</P>



<P>Whenever you start another copy of <TT>tcsh</TT> after you log in to the system,



it will execute the commands that are in the <TT>/etc/csh.cshrc</TT> file and then



check your home directory to see if there is a <TT>.tcshrc</TT> or a <TT>.cshrc</TT>



file there.



<CENTER>



<H3><A NAME="Heading24<FONT COLOR="#000077">tcsh Command Summary</FONT></H3>



</CENTER>



<P>Here are some of the most useful <TT>tcsh</TT> commands:







<UL>



	<LI><TT>alias</TT>: Used to set and display aliases, command nicknames that can be



	set by the user.



	<P>



	<LI>bg: Background command. Forces a suspended process to continue running in the



	background.



	<P>



	<LI><TT>bindkey</TT>: Enables users to change the editing actions that are associated



	with a key sequence.



	<P>



	<LI><TT>cd</TT>: Changes the current working directory to the directory specified.



	<P>



	<LI><TT>exit</TT>: Terminates the shell.



	<P>



	<LI><TT>fg</TT>: Foreground command. Forces a suspended process to continue running



	in the foreground.



	<P>



	<LI><TT>history</TT>: Enables users to display and modify the contents of the history



	list and the history file.



	<P>



	<LI><TT>kill</TT>: Terminates another process.



	<P>



	<LI><TT>logout</TT>: Terminates a login shell.



	<P>



	<LI><TT>set</TT>: Used to set the value of <TT>tcsh</TT> variables.



	<P>



	<LI><TT>source</TT>: Reads and executes the contents of a file. This command is discussed



	in more detail in Chapter 13.



	<P>



	<LI><TT>unalias</TT>: Used to remove aliases that have been defined using the <TT>alias</TT>



	command.



</UL>







<CENTER>



<H3><A NAME="Heading25<FONT COLOR="#000077">tcsh Variables</FONT></H3>



</CENTER>



<P>Here are some of the most useful <TT>tcsh</TT> variables:







<UL>



	<LI><TT>autocorrect</TT>: If this is set, <TT>tcsh</TT> will automatically try to



	correct command-line spelling errors.



	<P>



	<LI><TT>histfile</TT>: The name of the file that is used to store the command history.



	<P>



	<LI><TT>history</TT>: The size of the history list.



	<P>



	<LI><TT>home</TT>: The user's home directory.



	<P>



	<LI><TT>path</TT>: The search path that <TT>tcsh</TT> uses when looking for executable



	programs.



	<P>



	<LI><TT>prompt</TT>: The first-level prompt that is displayed on the command line.



	<P>



	<LI><TT>prompt2</TT>: The second-level prompt that is displayed when a <TT>for</TT>,



	<TT>foreach</TT>, or <TT>while</TT> loop is expecting input.



	<P>



	<LI><TT>prompt3</TT>: The third-level prompt that is displayed when <TT>tcsh</TT>



	has attempted to correct a spelling error in a command.



	<P>



	<LI><TT>savehist</TT>: This variable must be set to the number of history commands



	that you want to save, if you want <TT>tcsh</TT> to save the history list when you



	log out.



	<P>



	<LI><TT>watch</TT>: Contains a list of user terminal pairs to watch for logins and



	logouts.



</UL>







<CENTER>



<H3><A NAME="Heading26<FONT COLOR="#000077">Summary</FONT></H3>



</CENTER>



<P>The last three chapters have presented the fundamental commands and concepts of



the three most popular UNIX shells. <TT>tcsh</TT> is the most feature-rich shell



of those presented, but that doesn't necessarily mean that it's the best shell for



you to use. In the end, this decision will probably be based on your personal preference



as opposed to what features are offered.</P>







<P>The next chapter looks at the programming languages that are provided by each



of the shells we have discussed.



















</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -