rhl12.htm

来自「linux的初学电子书」· HTM 代码 · 共 1,692 行 · 第 1/3 页

HTM
1,692 行
字号

<BR>

<PRE>

<FONT COLOR="#000080">bindkey ^W kill-whole-line

bindkey ^S beginning-of-line</FONT></PRE>

<BR>

<A NAME="E68E87"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Other Neat Stuff</B></FONT></CENTER></H3>

<BR>

<P>tcsh 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.

<BR>

<BR>

<A NAME="E69E182"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Correcting Spelling Errors</B></FONT></CENTER></H4>

<BR>

<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 tcsh over any of the 
other shells. You can tell tcsh 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.

<BR>

<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.

<BR>

<P>For example, suppose you wanted to change to the /usr/X11R6/X11 directory, so you typed the following command on the command line:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">cd /usr/X11RT/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. tcsh will try to correct the spelling of the command. It would change the command to read

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">cd /usr/X11R6/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.

<BR>

<P>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, will tell 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:

<BR>

<PRE>

<FONT COLOR="#000080">set correct=cmd 

<BR>

<BR>or

<BR>

set correct=all</FONT></PRE>

<P>After you set the correct variable, whenever you enter a command that tcsh 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 all option and then entered the following command:

<BR>

<BR>

<PRE>

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

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

<BR>

<BR>

<PRE>

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

<P>If you respond to the prompt by pressing the y (yes) key, tcsh will execute the corrected command. If you respond to the prompt by pressing the n (no) key, tcsh will execute the command that you initially entered, which will in turn will cause an error 
message to be displayed.

<BR>

<P>If you respond to the prompt by pressing the e (edit) key, tcsh will put the command that you entered back on the command line and enable you to edit it.

<BR>

<BR>

<A NAME="E69E183"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Precommands</B></FONT></CENTER></H4>

<BR>

<P>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 will be executed before the command prompt 
is displayed on-screen. For example, assume that you set the precmd variable using the following command:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">alias precmd time</FONT></PRE>

<P>After this alias has been declared, the time command will always be executed before the command prompt is displayed on-screen.

<BR>

<BR>

<A NAME="E69E184"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Change Directory Commands</B></FONT></CENTER></H4>

<BR>

<P>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 might want to know something about a directory that you just entered.

<BR>

<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 cwdcmd. If this variable is aliased to a command, that command will be executed each time you 
change current working directories.

<BR>

<P>A common use for this variable is to display the current directory to the screen. This can be done by entering the command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">alias cwdcmd 'pwd'</FONT></PRE>

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

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>You should not put a cd command into cwdcmd. Doing so could cause an infinite loop that would cause you to lose control of tcsh.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E185"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Monitoring Logins and Logouts</B></FONT></CENTER></H4>

<BR>

<P>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.

<BR>

<P>The watch 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 tcsh to match any user or terminal. The syntax for setting the watch variable is

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">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.

<BR>

<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 jules to come to work in the morning, you could set the following watch variable:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">set watch=(jules any)</FONT></PRE>

<P>This command would inform you when a person with the user ID jules logged into 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:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">set watch=(5 jules any)</FONT></PRE>

<P>This will do the same thing as the first command, except it will check every five minutes instead of every 10 to see if jules has logged in.

<BR>

<BR>

<A NAME="E68E88"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Customizing </B><B>tcsh</B></FONT></CENTER></H3>

<BR>

<P>I've discussed many ways of customizing tcsh 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 tcsh.

<BR>

<P>Two initialization files are important to tcsh. 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.1.

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 12.1. Default csh.login file.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">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/X11r6/man:

_/usr/openwin/man

setenv MINICOM &quot;-c on&quot;

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

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

_$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 &#151;silent } ) then &gt;&amp; /dev/null

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

endif</FONT></PRE>

<P>This file, csh.login, can be found in the /etc directory. If you want to change any of the settings found in csh.login, you should copy it to your home directory and make the changes you want there.

<BR>

<P>The other file that tcsh makes use of is cshrc. The commands in this file are executed each time a copy of the tcsh program is run. Examples of the types of commands that usually appear in this file are aliases and variable declarations. This file, 
csh.cshrc, is also contained in the /etc directory. If you want to make changes to this file, you should copy it to your home directory and make your changes there.

<BR>

<P>When you first log in to Linux, tcsh executes the /etc/csh.cshrc file, followed by the /etc/csh.login file. It then checks your home directory to see if you have a personal copy of the csh.cshrc file. This file can be named either .tcshrc or .cshrc. If 
you have one of these files in your home directory, tcsh will execute it next.

<BR>

<P>tcsh next checks to see if you have your own copy of the csh.login file in your home directory. This file must be named .login. If you do have a .login file in your home directory, it will be executed next.

<BR>

<P>Whenever you start another copy of tcsh after you log in to the system, it will execute the commands that are in the /etc/csh.cshrc file and then check your home directory to see if there is a .tcshrc or a .cshrc file there.

<BR>

<BR>

<A NAME="E68E89"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>tcsh</B><B> Command Summary</B></FONT></CENTER></H3>

<BR>

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

<BR>

<UL>

<LI>alias: Used to set and display aliases, command nicknames that can be set by the user.

<BR>

<BR>

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

<BR>

<BR>

<LI>bindkey: Enables users to change the editing actions that are associated with a key sequence.

<BR>

<BR>

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

<BR>

<BR>

<LI>exit: Terminates the shell.

<BR>

<BR>

<LI>fg: Foreground command. Forces a suspended process to continue running in the foreground.

<BR>

<BR>

<LI>history: Enables users to display and modify the contents of the history list and the history file.

<BR>

<BR>

<LI>kill: Terminates another process.

<BR>

<BR>

<LI>logout: Terminates a login shell.

<BR>

<BR>

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

<BR>

<BR>

<LI>source: Reads and executes the contents of a file. This command is discussed in more detail in <A HREF="rhl13.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl13.htm">Chapter 13</A>.

<BR>

<BR>

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

<BR>

<BR>

</UL>

<BR>

<A NAME="E68E90"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>tcsh</B><B> Variables</B></FONT></CENTER></H3>

<BR>

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

<BR>

<UL>

<LI>autocorrect: If this is set, tcsh will automatically try to correct command-line spelling errors.

<BR>

<BR>

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

<BR>

<BR>

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

<BR>

<BR>

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

<BR>

<BR>

<LI>path: The search path that tcsh uses when looking for executable programs.

<BR>

<BR>

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

<BR>

<BR>

<LI>prompt2: The second-level prompt that is displayed when a for, foreach, or while loop is expecting input.

<BR>

<BR>

<LI>prompt3: The third-level prompt that is displayed when tcsh has attempted to correct a spelling error in a command.

<BR>

<BR>

<LI>savehist: This variable must be set to the number of history commands that you want to save, if you want tcsh to save the history list when you log out.

<BR>

<BR>

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

<BR>

<BR>

</UL>

<BR>

<A NAME="E68E91"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>

<BR>

<P>The last three chapters have presented the fundamental commands and concepts of the three most popular UNIX shells. tcsh 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.

<BR>

<P>The next chapter looks at the programming languages that are provided by each of the shells we have discussed.

<P ALIGN=LEFT>

<A HREF="rhl11.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl11.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="rhl13.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl13.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>


</BODY></HTML>



⌨️ 快捷键说明

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