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

📄 ch08_01.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 8] How the Shell Interprets What You Type</TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:34:06Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="part02.htm"TITLE="II. Let the Computer Do the Dirty Work "><LINKREL="prev"HREF="part02.htm"TITLE="II. Let the Computer Do the Dirty Work "><LINKREL="next"HREF="ch08_02.htm"TITLE="8.2 Introduction to bash"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="PART"HREF="part02.htm"TITLE="II. Let the Computer Do the Dirty Work "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: II. Let the Computer Do the Dirty Work "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 8</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch08_02.htm"TITLE="8.2 Introduction to bash"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 8.2 Introduction to bash"BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="CHAPTER"><H1CLASS="chapter"><ACLASS="title"NAME="UPT-CHP-8">8. How the Shell Interprets What You Type</A></H1><DIVCLASS="htmltoc"><P><B>Contents:</B><BR><ACLASS="sect1"HREF="#UPT-ART-1810"TITLE="8.1 What the Shell Does ">What the Shell Does </A><BR><ACLASS="sect1"HREF="ch08_02.htm"TITLE="8.2 Introduction to bash">Introduction to bash</A><BR><ACLASS="sect1"HREF="ch08_03.htm"TITLE="8.3 Introduction to tcsh">Introduction to tcsh</A><BR><ACLASS="sect1"HREF="ch08_04.htm"TITLE="8.4 Command Evaluation and Accidentally Overwriting Files">Command Evaluation and Accidentally Overwriting Files</A><BR><ACLASS="sect1"HREF="ch08_05.htm"TITLE="8.5 Command-Line Evaluation ">Command-Line Evaluation </A><BR><ACLASS="sect1"HREF="ch08_06.htm"TITLE="8.6 Output Command-Line Arguments ">Output Command-Line Arguments </A><BR><ACLASS="sect1"HREF="ch08_07.htm"TITLE="8.7 Setting Your Search Path ">Setting Your Search Path </A><BR><ACLASS="sect1"HREF="ch08_08.htm"TITLE="8.8 A Directory for Commands You Shouldn't Run ">A Directory for Commands You Shouldn't Run </A><BR><ACLASS="sect1"HREF="ch08_09.htm"TITLE="8.9 Wildcards Inside of Aliases ">Wildcards Inside of Aliases </A><BR><ACLASS="sect1"HREF="ch08_10.htm"TITLE="8.10 eval: When You Need Another Chance ">eval: When You Need Another Chance </A><BR><ACLASS="sect1"HREF="ch08_11.htm"TITLE="8.11 Which One Will bash Use? ">Which One Will bash Use? </A><BR><ACLASS="sect1"HREF="ch08_12.htm"TITLE="8.12 Which One Will the C Shell Use? ">Which One Will the C Shell Use? </A><BR><ACLASS="sect1"HREF="ch08_13.htm"TITLE='8.13 Is It "2&gt;&amp;1 file&quot; or "&gt; file 2&gt;&amp;1&quot;? Why?'>Is It &quot;2&gt;&amp;1 file&quot; or &quot;&gt; file 2&gt;&amp;1&quot;? Why?</A><BR><ACLASS="sect1"HREF="ch08_14.htm"TITLE="8.14 Bourne Shell Quoting ">Bourne Shell Quoting </A><BR><ACLASS="sect1"HREF="ch08_15.htm"TITLE="8.15 Differences Between Bourne and C Shell Quoting ">Differences Between Bourne and C Shell Quoting </A><BR><ACLASS="sect1"HREF="ch08_16.htm"TITLE="8.16 Quoting Handles Special Characters in Filenames ">Quoting Handles Special Characters in Filenames </A><BR><ACLASS="sect1"HREF="ch08_17.htm"TITLE="8.17 verbose and echo Variables Show Quoting ">verbose and echo Variables Show Quoting </A><BR><ACLASS="sect1"HREF="ch08_18.htm"TITLE="8.18 Here Documents ">Here Documents </A><BR><ACLASS="sect1"HREF="ch08_19.htm"TITLE='8.19 "Special&quot; Characters and Operators '>&quot;Special&quot; Characters and Operators </A><BR><ACLASS="sect1"HREF="ch08_20.htm"TITLE="8.20 How Many Backslashes?">How Many Backslashes?</A></P><P></P></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1810">8.1 What the Shell Does </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-1810-IX-COMMANDS-SHELL-INTERPRETATION-OF"></A><ACLASS="indexterm"NAME="UPT-ART-1810-IX-SHELLS-INTERPRETING-COMMANDS"></A>As we've said, the shell is just another program. It's responsiblefor interpreting the commands you type; there are four or fivecommonly used shells, and several other<SPANCLASS="link">variants (<ACLASS="linkend"HREF="ch01_08.htm"TITLE="There Are Many Shells ">1.8</A>)</SPAN>kicking around.</P><PCLASS="para">Interpreting your commands might seem simple enough, but a lot ofthings happen between the time you press RETURN and the time thecomputer actually does what you want. The process of interpretationis very complex: the shell has to break the command into words, expand <SPANCLASS="link">aliases (<ACLASS="linkend"HREF="ch10_02.htm"TITLE="Aliases for Common Commands ">10.2</A>)</SPAN>,<SPANCLASS="link">history operators (<ACLASS="linkend"HREF="ch11_01.htm#UPT-ART-4920"TITLE="The Lessons of History ">11.1</A>)</SPAN>,and<SPANCLASS="link">shell and environment variables (<ACLASS="linkend"HREF="ch06_08.htm"TITLE="Shell Variables ">6.8</A>, <ACLASS="linkend"HREF="ch06_01.htm#UPT-ART-1170"TITLE="What Environment Variables Are Good For ">6.1</A>)</SPAN>.It also <SPANCLASS="link">sets up standard input and output streams (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>and performs a lot of other tasks. Indeed, if a command looks rightbut doesn't work right, the cause is probably either:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-7414"></A>File permissions are set incorrectly.</P></LI><LICLASS="listitem"><PCLASS="para">You don't understand how the shell is processing your command line.</P></LI></UL><PCLASS="para">I'd say that file permission problems are more common, but it's aclose call. File permission problems are usually easyto understand, once you know what to look for, but the rules by whicha shell interprets your command lineare another thing altogether. Lest I scare you, we'll try to go slowwith this material. Although it's difficult, understanding how theshell parses your commands is important to becoming a power user.</P><PCLASS="para">In this chapter, we'll look at how a UNIX shell interprets commands. Thestandard shells (the C shell, Bourne shell, and Korn shell) havesimilar interpretation rules. The C shell can be tricky at times,mostly because its behavior isn't as well defined as the others.However, there's nothing &quot;magical&quot; about these rules. Tomorrowmorning, you may grab some new shell from<SPANCLASS="link">the Net (<ACLASS="linkend"HREF="glossary.htm#UPT-ART-1010"TITLE="Glossary">52.9</A>)</SPAN>,and find out thatit has a new and different way of interpreting commands. Forbetter or worse, that's what UNIX is all about.</P><PCLASS="para">As part of this discussion, we'll cover quoting, which is themechanism by which you can turn off the special meanings that the shell assignsto some characters. Quoting is an integral part of command-lineprocessing; it allows you to control what the shell will do to yourcommands.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="PART"HREF="part02.htm"TITLE="II. Let the Computer Do the Dirty Work "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: II. Let the Computer Do the Dirty Work "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch08_02.htm"TITLE="8.2 Introduction to bash"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 8.2 Introduction to bash"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">II. Let the Computer Do the Dirty Work </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">8.2 Introduction to bash</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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