📄 ch01_02.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.2 Who Listens to What You Type? </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:30:53Z"><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="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_01.htm"TITLE="1.1 What's Special About UNIX? "><LINKREL="next"HREF="ch01_03.htm"TITLE="1.3 Programs Are Designed to Work Together "></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="SECT1"HREF="ch01_01.htm"TITLE="1.1 What's Special About UNIX? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.1 What's Special About UNIX? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_03.htm"TITLE="1.3 Programs Are Designed to Work Together "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.3 Programs Are Designed to Work Together "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1002">1.2 Who Listens to What You Type? </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-711"></A><ACLASS="indexterm"NAME="AUTOID-713"></A>Probably the single most important concept for would-be powerusers to grasp is that you don't talk to UNIX directly.Instead, you talk to a program called the <EMCLASS="emphasis">shell</EM>.The shell protects UNIX from the user (and the userfrom UNIX).</P><PCLASS="para">The UNIX operating system proper is referred to as<SPANCLASS="link">the kernel (<ACLASS="linkend"HREF="ch01_14.htm"TITLE="The Kernel and Daemons ">1.14</A>)</SPAN>.Usually, only programs talk to the kernel (through<SPANCLASS="link">system calls (<ACLASS="linkend"HREF="glossary.htm#UPT-ART-1010"TITLE="Glossary">52.9</A>)</SPAN>).Users talk to theshell, which interprets their commands and either executes themdirectly or passes them on to other programs. These programsin turn request lower-level services from the kernel.</P><PCLASS="para">For example, when you type a command to display files whose four-character filenamesstart with the letter "m":</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch01_16.htm"TITLE="1.16 Wildcards ">???</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>cat m???</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-725"></A>it is the shell that finds the filenames, makes a complete list ofthem, andcalls the<SPANCLASS="link"><EMCLASS="emphasis">cat</EM> (<ACLASS="linkend"HREF="ch25_02.htm"TITLE="Four Ways to Skin a cat ">25.2</A>)</SPAN>command to ask it to print the expanded list.The <EMCLASS="emphasis">cat</EM>command calls on the kernel to find each file on the disk andprint its contents as a stream of characters on the display.</P><PCLASS="para">Why is this important? First of all, you can choose between<SPANCLASS="link">several different shells (<ACLASS="linkend"HREF="ch01_08.htm"TITLE="There Are Many Shells ">1.8</A>)</SPAN>,each of which may have different rules for interpreting command lines.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-733"></A>Second, the shell has to interpret the command line you typeand package it up for the command you are calling. Becausethe shell reads the command line first, it's important tounderstand just how the shell changes what it reads.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-737"></A>For example, one basic rule is that the shell uses "white space"(spaces or tabs) to separate each"argument" of a command.But sometimes, you want the shell tointerpret its arguments differently.For example, if you arecalling<SPANCLASS="link"><EMCLASS="emphasis">grep</EM> (<ACLASS="linkend"HREF="ch27_01.htm#UPT-ART-7420"TITLE="Different Versions of grep ">27.1</A>)</SPAN>,a program for searching through files for a matching line oftext, you might want to supply an entire phrase as a singleargument. The shell lets you do this by<SPANCLASS="link">quoting (<ACLASS="linkend"HREF="ch08_14.htm"TITLE="Bourne Shell Quoting ">8.14</A>)</SPAN>arguments. For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>grep "UNIX Power Tools" articles/*</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Understanding how the shell interprets the command line, andwhen to keep it from doing so, can be very important in a lotof special cases, especially when dealing with<SPANCLASS="link">wildcards (<ACLASS="linkend"HREF="ch01_16.htm"TITLE="Wildcards ">1.16</A>)</SPAN>like the <CODECLASS="literal">*</CODE> (asterisk) above.Article<ACLASS="xref"HREF="ch08_05.htm"TITLE="Command-Line Evaluation ">8.5</A>explains more about how the shell interprets what you type.</P><PCLASS="para">You can think of the relationship of the kernel, the shell, andvarious UNIX utilities and applications as looking like<ACLASS="xref"HREF="ch01_02.htm#UPT-ART-1002-FIG-0"TITLE="Relationship of Kernel, Shell, Utilities, and Applications">Figure 1.1</A>.</P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-1002-FIG-0">Figure 1.1: Relationship of Kernel, Shell, Utilities, and Applications</A></H4><IMGCLASS="graphic"SRC="figs/1002.gif"ALT="Figure 1.1"><ACLASS="indexterm"NAME="AUTOID-754"></A><ACLASS="indexterm"NAME="AUTOID-757"></A><PCLASS="para">Note that there are some interactive commands that take inputdirectly from the user, without intervention from the shell.The shell's only job is to start them up. A text editor, amail program, oralmost any application program (desktop publishing, spreadsheet)includes its own command interpreter with its own rules.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</SPAN></P></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="SECT1"HREF="ch01_01.htm"TITLE="1.1 What's Special About UNIX? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.1 What's Special About UNIX? "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="ch01_03.htm"TITLE="1.3 Programs Are Designed to Work Together "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.3 Programs Are Designed to Work Together "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.1 What's Special About UNIX? </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">1.3 Programs Are Designed to Work Together </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 & 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 + -