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

📄 unx13.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<A HREF="#I96">Requesting Notification of Background Job Status Changes&#151;notify</A></LI>

<LI>

<A HREF="#I97">Controlling Background Process Dispatch Priority&#151;nice</A></LI>

<LI>

<A HREF="#I98">Signaling a Process&#151;kill</A></LI></UL>

<LI>

<A HREF="#I99">Using the Shell's Hash Table</A></LI>

<UL>

<LI>

<A HREF="#I100">Determining the Effectiveness of the Hash Table&#151;hashstat</A></LI>

<LI>

<A HREF="#I101">Rebuilding the Hash Table&#151;rehash</A></LI>

<LI>

<A HREF="#I102">Disabling the Use of the Hash Table&#151;unhash</A></LI></UL>

<LI>

<A HREF="#I103">Managing Resource Limits&#151;limit and unlimit</A></LI>

<UL>

<LI>

<A HREF="#I104">Displaying or Setting Maximum Resource Limits&#151;limit</A></LI>

<LI>

<A HREF="#I105">Canceling a Previous limit Command&#151;unlimit</A></LI></UL>

<LI>

<A HREF="#I106">Summary</A></LI></UL></UL></UL>



<H1 ALIGN="CENTER">

<CENTER><A ID="I1" NAME="I1">

<BR>

<FONT SIZE=5><A ID="I2" NAME="I2"></A><B>13 &#151; C Shell</B>

<BR></FONT></A></CENTER></H1>

<H5 ALIGN="CENTER">

<CENTER><A ID="I3" NAME="I3">

<FONT SIZE=3><B>By John Valley</B>

<BR></FONT></A></CENTER></H5>

<P>As a UNIX user, you have a choice of shells available to you. These are the Bourne shell, the C shell, and the Korn shell. The C shell&#151;the subject of this chapter&#151;is one of the more popular shells available in UNIX. Chronologically, it was 
developed after the Bourne shell and before the Korn shell. The C shell incorporates many features of the Bourne shell and adds many new ones that make your UNIX sessions more efficient and convenient.

<BR></P>

<P>There are advantages and disadvantages to each shell. You may wish to review Chapter 14, &quot;Which Shell Is Right for You?&quot; to help you decide which one to use.

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I4" NAME="I4">

<FONT SIZE=4><B>A Little History</B>

<BR></FONT></A></CENTER></H3>

<P>The Bourne and Korn shells were created at AT&amp;T's Bell Labs, which, not coincidentally, is also where UNIX originated. Bell Labs is not the only organization that contributed to the development of UNIX, however. The Department of Computer Science at 

the Berkeley campus, University of California, played a very important role.

<BR></P>

<P>As you might have already read, the early versions of UNIX were made available only to colleges and universities under a rather restrictive licensing arrangement: UNIX could be used outside of AT&amp;T only for &quot;research purposes.&quot; At 
Berkeley, interest in UNIX was very high. The computer science labs added many new features to UNIX and offered their version to other universities as well. The Berkeley version soon became the more popular version, not only because of its many new 
features and extensions, but also because Berkeley, unlike Bell Labs, offered maintenance and support to other user groups. Given this fact, it shouldn't be surprising that by the late 1970s, the BSD version (Berkeley Software Distribution) was the 
dominant variant of UNIX in use.

<BR></P>

<P>One of the additions to UNIX was a new shell, written by Bill Joy (also the author of the vi text editor). Joy did not pattern his shell after the Bourne shell; indeed, to judge by results, he apparently felt that the Bourne shell syntax was clumsy and 

nonintuitive. As a syntax model, he chose the C programming language. The C shell commands, especially if, while, and the other structured programming statements, are somewhat similar in syntax to the equivalent statements in C. A shell is quite a 
different animal from a compiler, however, so the C programming language served only as a model; many forms and structures in the C shell have nothing to do with the C programming language.

<BR></P>

<P>Because the C shell is not just an extension of the Bourne shell syntax, this chapter will cover all aspects of C shell operation; it can therefore be read independently from Chapter 11, &quot;Bourne Shell,&quot; and Chapter 12, &quot;Korn Shell.&quot;

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I5" NAME="I5">

<FONT SIZE=4><B>Invoking C Shell</B>

<BR></FONT></A></CENTER></H3>

<P>Each time you log in to UNIX, you're placed in an interactive shell referred to as your login shell. If your login shell is C shell, you can tell by its command-line prompt: the percent sign (%). The C shell prompt differs from the dollar sign prompt 
($) of the Bourne shell to remind you that you're using the C shell. You can customize your keyboard prompt when using the C shell; for more information see the definition of prompt in the section titled &quot;Variables&quot; later in this chapter.

<BR></P>

<P>If your login shell is not C shell, and C shell is available on your system, you can invoke it as an interactive shell from the command line. Even when you're already running the C shell, there will be times when you want to launch the C shell again, 
for example to run a shell script or to temporarily change the shell's options. To invoke the C shell interactively, use the following command:

<BR></P>

<PRE>$ csh

%</PRE>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> The csh command is usually located in either the /bin or the /usr/bin directory. Because both directories are usually in your search path, you shouldn't have any trouble finding the csh command if 
your system has it. If you don't find it right away, you might look in the directory /usr/ucb (standard home for BSD components in a UNIX System V system), or in /usr/local/bin, home for programs your shop has acquired that weren't provided with the 
original system. Remember, though, that the C shell was for many years available only to those shops using the BSD variant of UNIX; unlike the Bourne shell, there is no guarantee that you will have the csh command on your system.

<BR></NOTE>

<HR ALIGN=CENTER>

<P>The csh command also supports a number of options and arguments (described later in this chapter in the section titled &quot;Shell Options&quot;), but most of them are not relevant to running an interactive shell.

<BR></P>

<P>Whenever csh is invoked, whether as the login shell or as a subshell, it loads and executes a profile script named .cshrc. If it is a login shell, the C shell will also execute a profile script on startup named .login, and another on exit named .logout. 

Note that the .login script is executed after .cshrc, not before. For additional information about C shell profile scripts, see the section titled &quot;Customizing Your Shell Environment&quot; later in this chapter.

<BR></P>

<P>Most versions of the C shell import environment variables such as <I>PATH</I> into local array variables at startup. The C shell does not refer to the public environment variables (including <I>PATH</I>) for its own operation. This means that usually 
you'll want to maintain the <I>path</I> variable for directory searches, not <I>PATH</I>. Some versions of the C shell do not properly import environment variables, with confusing results. If it appears that you have no search path set, but the <I>PATH</I> 

variable is set and accurate (as shown by echo $PATH), check that the variable <I>path</I> has a matching value. If not, you'll need to import critical environment variables into local variables yourself.

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> If you are familiar with Bourne shell, you won't notice much difference working with the C shell unless you use advanced shell features such as variables, command replacement, and so on.

<BR>

<BR>Important differences do exist, however. Among these are the set of punctuation characters having special meaning to the shell (often called metacharacters). The C shell is sensitive to all the special characters of the Bourne shell, as well as the 
tilde (~), the commercial at sign (@), and the exclamation point (!). Don't forget to quote or escape these characters when writing commands unless you intend their special shell meaning. (See the section &quot;Quoting and Escaping from Special 
Characters&quot; for a discussion of the details.)

<BR></NOTE>

<HR ALIGN=CENTER>

<H3 ALIGN="CENTER">

<CENTER><A ID="I6" NAME="I6">

<FONT SIZE=4><B>Shell Basics</B>

<BR></FONT></A></CENTER></H3>

<P>When you enter commands at the shell prompt, you are providing input to the shell. The shell sees a line of input as a string of characters terminated with a newline character that is usually the result of pressing return on your keyboard. That input 
can be anything from a single, simple command to multiple commands joined with command operators. Each command line that you enter is actually a shell statement. In addition to providing input to the shell manually by entering shell statements on the 
command line, you can also provide input to the shell by putting shell statements into a file and executing the file.

<BR></P>

<P>The next section covers the basics of interacting with the shell by entering shell statements on the command line. (Of course, anything that you can enter on the command line can also be put into a file for later, &quot;canned&quot; execution. Such 
files are called shell scripts.) The section following is titled &quot;Shell Statements&#151;A Closer Look,&quot; which provides a more detailed, technical look at components of shell statements. If you plan to write shell scripts, you'll definitely want 
to read this section.

<BR></P>

<P>When you finish this section, you will feel like you know a lot about the shell, but this is just the beginning. In addition to its basic service of providing a means to instruct the computer, the shell also provides a number of tools you can use to 
expedite your work flow. These tools, or features of the shell, are described in subsequent sections of this chapter.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I7" NAME="I7">

<FONT SIZE=3><B>Executing Commands&#151;The Basics</B>

<BR></FONT></A></CENTER></H4>

<P>C shell accepts several types of commands as input: UNIX commands, built-in shell commands, user-written commands, and command aliases. This section describes the different types of commands you can execute and the various ways you can execute commands.



<BR></P>

<H5 ALIGN="CENTER">

<CENTER><A ID="I8" NAME="I8">

<FONT SIZE=3><B>Command Names as Shell Input</B>

<BR></FONT></A></CENTER></H5>

<P>As you know, you execute a command by entering the command's name. The C shell supports any of the following as command names:

<BR></P>

<UL>

<LI>Built-in C shell command. The shell provides a number of commands implemented within the shell program itself: invoking a built-in command therefore executes very quickly because no program files need to be loaded. A built-in command is always invoked 

by a simple name, never by a pathname.

<BR>

<BR>Because the shell first checks a command name for built-in commands before searching for a file of the same name, you cannot redefine a built-in command with a shell script. The next section, &quot;Built-In Shell Commands,&quot; briefly describes each 

one; detailed descriptions with examples of how to use these commands are presented in the task-oriented sections of this chapter.

<BR>

<BR></LI>

<LI>Filename. You can specify the filename or a relative or absolute pathname of a file as a command. The file must be marked executable and must be either a binary load file or a shell script in the C shell language. The C shell cannot process shell 
scripts written for the Bourne or Korn shells. (See the section titled &quot;Shell Programming&quot; later in this chapter for notes about using shell scripts with the C shell.)

<BR>

<BR>All UNIX commands are provided as executable files in the /bin or /usr/bin directories. You invoke a UNIX command by entering its filename or full pathname.

<BR>

<BR>Examples of invoking an executable program file include the following:

<BR>

<BR>% cat big.script

<BR>% /usr/bin/cat big.script

<BR>% /usr/ucb/cc myprog.c

<BR>% ../paylist paymast

<BR>

<BR></LI>

<LI>Command alias. A command alias is a name you define using the alias shell built-in command.

<BR>

<BR>An alias can have the same name as a shell built-in command or an executable file. You can always invoke an executable file having the same name as an alias by using the file's full pathname. An alias having the same name as a built-in command, 
however, effectively hides the built-in command. Aliases are described in detail in the section titled &quot;Aliases&quot; later in this chapter.

<BR>

<BR></LI></UL>

<H5 ALIGN="CENTER">

<CENTER><A ID="I9" NAME="I9">

<FONT SIZE=3><B>Built-In Shell Commands</B>

<BR></FONT></A></CENTER></H5>

<P>C shell provides a number of commands implemented within the shell program itself. Built-in commands execute very quickly because no external program file needs to be loaded. Table 13.1 lists the commands alphabetically along with a brief description of 

each one. The remainder of this chapter groups these commands into subsections dedicated to particular tasks you'll perform in the shell and describes how to use each command.

<BR></P>

<UL>

<LH><B>Table 13.1. Built-in commands for C shell.</B>

<BR></LH></UL>

<TABLE BORDER>

<TR>

<TD>

<PRE><I>Command</I>

<BR></PRE>

<TD>

<PRE><I>Description</I>

<BR></PRE>

<TR>

<TD>

<P>alias</P>

<TD>

<P>Define or list a command alias</P>

<TR>

<TD>

<P>bg</P>

<TD>

<P>Background execution</P>

<TR>

<TD>

<P>break</P>

<TD>

<P>Breaking out of a loop</P>

<TR>

<TD>

<P>breaksw</P>

<TD>

<P>Exit from a switch statement</P>

<TR>

<TD>

<P>case</P>

<TD>

<P>Begin a case in switch</P>

<TR>

<TD>

<P>cd</P>

<TD>

<P>Change directory</P>

<TR>

<TD>

<P>chdir</P>

<TD>

<P>Change directory</P>

<TR>

<TD>

<P>continue</P>

<TD>

<P>Begin the next loop iteration immediately</P>

<TR>

<TD>

<P>default</P>

<TD>

<P>Label for the default case in switch</P>

<TR>

<TD>

<P>dirs</P>

<TD>

<P>List the directory stack</P>

<TR>

<TD>

<P>echo</P>

<TD>

<P>Echo arguments to standard output</P>

<TR>

<TD>

<P>eval</P>

<TD>

<P>Rescan a line for substitutions</P>

<TR>

<TD>

<P>exec</P>

<TD>

<P>Invoke a new shell</P>

<TR>

<TD>

⌨️ 快捷键说明

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