📄 257-260.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=257-260//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="254-257.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch14/261-264.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading17"></A><FONT COLOR="#000077">Customizing tcsh</FONT></H3>
<P>We’ve shown many ways of customizing <TT>tcsh</TT> in this chapter. If you simply 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 are executed each time you start <TT>tcsh</TT>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>If you make even a small mistake editing the <TT>tcsh</TT>files, you can cause problems when logging in. For this reason, make safety backup copies before you edit and verify each of your edits carefully before you save the new file.<HR></FONT>
</BLOCKQUOTE>
<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 in to Linux. The contents of the default login file are as follows:</P>
<!-- CODE //-->
<PRE>
if ($?prompt) then
#this means that the shell is interactive
umask 022
set cdpath = ( /usr/spool )
set notify
set history = 100
set histfile = .history
# The savehist variable is set to tell tcsh to
# save the history list to the history file on
# logout. The value of 25 means that tcsh will
# save the last 25 commands to the history file.
set savehist = 25
setenv OPENWINHOME /usr/openwin
setenv MANPATH /usr/local/man:/usr/man/preformat:/usr/man:/usr/X11/man:
/usr/openwin/man
setenv MINICOM “-c on”
setenv HOSTNAME “‘cat /etc/HOSTNAME‘”
set path = ( $path /usr/X11/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 “$term”‘
# setenv term console
if ! $?TERM setenv TERM console
set prompt = “%m:%~%# “
alias ls ’ls -F’
if ( { tty --silent } ) then >& /dev/null
echo “”;fortune;echo “”
endif
</PRE>
<!-- END CODE //-->
<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>, copy it to your home directory 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, copy it to your home directory 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> executes it next.</P>
<TT>tcsh</TT> then 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 is executed next.
<P>Whenever you start another copy of <TT>tcsh</TT> after you log in to the system, it executes the commands that are in the <TT>/etc/csh.cshrc</TT> file and then checks your home directory to see if there is a <TT>.tcshrc</TT> or a <TT>.cshrc</TT> file there.</P>
<H3><A NAME="Heading18"></A><FONT COLOR="#000077">tcsh Command Summary</FONT></H3>
<P>Here are some of the most useful <TT>tcsh</TT> commands:</P>
<DL>
<DD><B>•</B> <TT>alias</TT>: Used to set and display aliases, command nicknames that can be set by the user.
<DD><B>•</B> <TT>bg</TT>: Background command. Forces a suspended process to continue running in the background.
<DD><B>•</B> <TT>bindkey</TT>: Enables users to change the editing actions that are associated with a key sequence.
<DD><B>•</B> <TT>cd</TT>: Changes the current working directory to the directory specified.
<DD><B>•</B> <TT>exit</TT>: Terminates the shell.
<DD><B>•</B> <TT>fg</TT>: Foreground command. Forces a suspended process to continue running in the foreground.
<DD><B>•</B> <TT>history</TT>: Enables users to display and modify the contents of the history list and the history file.
<DD><B>•</B> <TT>kill</TT>: Terminates another process.
<DD><B>•</B> <TT>logout</TT>: Terminates a login shell.
<DD><B>•</B> <TT>set</TT>: Used to set the value of <TT>tcsh</TT> variables.
<DD><B>•</B> <TT>source</TT>: Reads and executes the contents of a file. This command is discussed in more detail in Chapter 14.
<DD><B>•</B> <TT>unalias</TT>: Used to remove aliases that have been defined using the <TT>alias</TT> command.
</DL>
<H3><A NAME="Heading19"></A><FONT COLOR="#000077">tcsh Variables</FONT></H3>
<P>Here are some of the most useful <TT>tcsh</TT> variables:</P>
<DL>
<DD><B>•</B> <TT>autocorrect</TT>: If this is set, <TT>tcsh</TT> automatically tries to correct command-line spelling errors.
<DD><B>•</B> <TT>histfile</TT>: The name of the file that is used to store the command history.
<DD><B>•</B> <TT>history</TT>: The size of the history list.
<DD><B>•</B> <TT>home</TT>: The user’s home directory.
<DD><B>•</B> <TT>path</TT>: The search path that <TT>tcsh</TT> uses when looking for executable programs.
<DD><B>•</B> <TT>prompt</TT>: The first-level prompt that displays on the command line.
<DD><B>•</B> <TT>prompt2</TT>: The second-level prompt that displays when a <TT>for</TT>, <TT>foreach</TT>, or <TT>while</TT> loop is expecting input.
<DD><B>•</B> <TT>prompt3</TT>: The third-level prompt that displays when <TT>tcsh</TT> is attempting to correct a spelling error in a command.
<DD><B>•</B> <TT>savehist</TT>: This variable must be set to the number of <TT>history</TT> commands that you want to save, if you want <TT>tcsh</TT> to save the history list when you log out.
<DD><B>•</B> <TT>watch</TT>: Contains a list of user terminal pairs to watch for logins and logouts.
</DL>
<H3><A NAME="Heading20"></A><FONT COLOR="#000077">Summary</FONT></H3>
<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. You may want to learn about other subjects before of moving on to the C shell. To learn about:</P>
<DL>
<DD>Using editors to create and edit files, read Chapter 16, “Text Editors: <TT>vi</TT> and <TT>emacs</TT>.”
<DD>Sending output to your printers under Linux, see Chapter 20, “Printing.”
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="254-257.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch14/261-264.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 + -