203-206.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 98 行

HTML
98
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:bash</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=11//-->

<!--PAGES=203-206//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch10/199-202.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="207-209.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 11<BR>bash

</FONT></H2>

<P><I>by Rick McMullin and Tim Parker</I></P>

<DL>

<DT><B>In This Chapter</B>

<DT>&#149;&nbsp;&nbsp; Shells in a nutshell

<DT>&#149;&nbsp;&nbsp; The Bourne again shell

<DT>&#149;&nbsp;&nbsp; Customizing bash

<DT>&#149;&nbsp;&nbsp; bash command summary

</DL>

<P>This chapter and the two that follow look at the shells available to you under Linux in a little more detail. Most Linux systems come with several shells, including <TT>bash</TT>, <TT>pdksh</TT>, and <TT>tcsh</TT>. We&#146;ll start with <TT>bash</TT> (Bourne Again Shell) because it&#146;s the default shell used by Linux and the most popular shell for new users. We&#146;ll also look at the most commonly used <TT>bash</TT> commands and the environment variables <TT>bash</TT> uses. By the end of this chapter, you should be able to work faster and more efficiently with <TT>bash</TT>.</P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Shells in a Nutshell</FONT></H3>

<P>What is a shell, anyway? It seems to be a word used all the time in Linux, but the exact meaning is vague for many new users (and some veterans). This section explains what a shell program is and why it is so important when using Linux.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">What Is a Shell?</FONT></H4>

<P>The shell is a program used to interface between you (the user) and Linux (or, more accurately, between you and the Linux kernel). Figure 11.1 illustrates the relationship between the user, the shell, and the Linux kernel. Every command you type at a prompt on your screen is interpreted by the shell, then passed to the Linux kernel.

</P>

<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/11-01.jpg',274,516 )"><IMG SRC="images/11-01t.jpg"></A>

<BR><A HREF="javascript:displayWindow('images/11-01.jpg',274,516)"><FONT COLOR="#000077"><B>Figure 11.1.</B></FONT></A>&nbsp;&nbsp;The relationship between the user and the shell.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>If you are familiar with MS-DOS, you will recognize this relationship as almost identical to the relationship between a DOS user and the COMMAND.COM program. The only real difference is that in the DOS world, no distinction is made between the COMMAND.COM program and DOS (or to be more accurate, the DOS kernel).<HR></FONT>

</BLOCKQUOTE>

<P>The shell is a command-language interpreter. It has its own set of built-in shell commands. The shell can also make use of all of the Linux utilities and application programs that are available on the system.

</P>

<P>Whenever you enter a command it is interpreted by the Linux shell. For example, in earlier chapters when you were introduced to the Linux file- and directory-manipulation commands, all of the sample commands entered at the command prompt were interpreted by whichever Linux shell you were using.</P>

<P>Some of the commands, such as the print working directory (<TT>pwd</TT>) command, are built into the Linux <TT>bash</TT> shell. Other commands, such as the copy command (<TT>cp</TT>) and the remove command (<TT>rm</TT>), are separate executable programs that exist in one of the directories in the file system. As the user, you don&#146;t know (or probably care) if the command is built in to the shell or is a separate program. Figure 11.2 shows how the shell performs this command interpretation.</P>

<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/11-02.jpg',451,248 )"><IMG SRC="images/11-02t.jpg"></A>

<BR><A HREF="javascript:displayWindow('images/11-02.jpg',451,248)"><FONT COLOR="#000077"><B>Figure 11.2.</B></FONT></A>&nbsp;&nbsp;Command interpretation by the shell.</P>

<P>Figure 11.2 illustrates the steps that the shell takes to figure out what to do with user commands. It first checks to see whether the command is one of its own built-in commands (such as <TT>cd</TT> or <TT>pwd)</TT>. If the command is not one of these built-in items, the shell checks to see if it is an application program. <I>Application programs</I> can be utility programs that are part of Linux, such as <TT>ls</TT> and <TT>rm</TT>, or they can be application programs that are either purchased commercially, such as <TT>xv</TT>, or are available as public domain software, such as <TT>ghostview</TT>.</P>

<P>The shell tries to find these application programs by looking in all of the directories that are in your search path. As we mentioned in an earlier chapter, the <I>path</I> is a list of directories where executable programs can be found. If the command that is entered is not an internal shell command and is not an executable file in your path, an error message is displayed similar to this one:</P>

<!-- CODE SNIP //-->

<PRE>

&#36; doit

doit: not found

</PRE>

<!-- END CODE SNIP //-->

<P>As the last step in running a successful command, the shell&#146;s internal commands and all of the application programs are eventually broken down into system calls and passed to the Linux kernel.

</P>

<P>Another important aspect of the shell is that it contains a very powerful interpretive programming language. This language is similar in function to the MS-DOS interpreted language, but is much more flexible. The shell programming language supports most of the programming constructs found in high-level languages, such as looping, functions, variables, and arrays.</P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">How the Shell Gets Started</FONT></H4>

<P>Earlier in this chapter you learned that the shell is the main method through which a user interacts with the Linux kernel. But how does this program get initialized to do so? The shell is started after you successfully log in to the system, and it continues to be the main method of interaction between the user and the kernel until you log out.

</P>

<P>Each user on your system has a default shell. The <I>default shell</I> for each user is specified in the system password file, called <TT>/etc/passwd</TT>. The <I>system password file</I> contains, among other things, each person&#146;s user ID, an encrypted copy of each user&#146;s password, and the name of the program to run immediately after a user logs in to the system. The program specified in the password file does not have to be one of the Linux shells, but it almost always is.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch10/199-202.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="207-209.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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