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

📄 ch01_03.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.3 Programs Are Designed to Work Together </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:30:55Z"><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_02.htm"TITLE="1.2 Who Listens to What You Type? "><LINKREL="next"HREF="ch01_04.htm"TITLE="1.4 Using Pipes to Create a New Tool "></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_02.htm"TITLE="1.2 Who Listens to What You Type? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.2 Who Listens to What You Type? "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_04.htm"TITLE="1.4 Using Pipes to Create a New Tool "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.4 Using Pipes to Create a New Tool "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1006">1.3 Programs Are Designed to Work Together </A></H2><PCLASS="para">As pointed out by Kernighan and Pike in their classic book, <EMCLASS="emphasis">The UNIXProgramming Environment</EM>, there are a number ofprinciples that distinguish the UNIX environment.One key concept is that programs are tools.And like all good tools, they should be specific in function, but usable formany different purposes.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-768"></A>In order for programs to become general-purpose tools, they must bedata-independent.This means three things:</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">Within limits, the output of any programshould be usable as the input to another.</P></LI><LICLASS="listitem"><PCLASS="para">All of the information needed by a programshould either be contained in the data stream passedto it or specified on the command line.A program should not prompt for input or do unnecessaryformatting of output. In most cases, this means that UNIXprograms work with plain text files that don't contain &quot;non-printable&quot;or &quot;control&quot; characters.</P></LI><LICLASS="listitem"><PCLASS="para">If no arguments are given, a programshould read the standard input (usually the terminalkeyboard) and write the standard output (usuallythe terminal screen).</P></LI></OL><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-779"></A>Programs that can be used in this way are often called <EMCLASS="emphasis">filters</EM>.</P><PCLASS="para">One of the most important consequences ofthese guidelines is that programs can be strung together in &quot;pipelines&quot; inwhich the output of oneprogram is used as the input of another.<ACLASS="indexterm"NAME="AUTOID-783"></A><ACLASS="indexterm"NAME="AUTOID-786"></A>A vertical bar (<CODECLASS="literal">|</CODE>) represents the<SPANCLASS="link">pipe (<ACLASS="linkend"HREF="ch01_04.htm"TITLE="Using Pipes to Create a New Tool ">1.4</A>)</SPAN>:it means &quot;take theoutput of the program on the left and feed it into the program on theright.&quot;</P><PCLASS="para">For example, you can pipe the output of a search programto another program that sorts the output, and thenpipe the result to the printer program or<SPANCLASS="link">redirect it to a file (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>.</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_02.htm"TITLE="1.2 Who Listens to What You Type? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.2 Who Listens to What You Type? "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_04.htm"TITLE="1.4 Using Pipes to Create a New Tool "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.4 Using Pipes to Create a New Tool "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.2 Who Listens to What You Type? </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.4 Using Pipes to Create a New Tool </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 + -