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

📄 ch13_05.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 13] 13.5 Redirection in C Shell: Capture Errors, Too? </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:36:43Z"><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="ch13_01.htm"TITLE="13. Redirecting Input and Output"><LINKREL="prev"HREF="ch13_04.htm"TITLE="13.4 Problems Piping to a Pager "><LINKREL="next"HREF="ch13_06.htm"TITLE="13.6 Safe I/O Redirection with noclobber "></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="ch13_04.htm"TITLE="13.4 Problems Piping to a Pager "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 13.4 Problems Piping to a Pager "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 13<BR>Redirecting Input and Output</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch13_06.htm"TITLE="13.6 Safe I/O Redirection with noclobber "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 13.6 Safe I/O Redirection with noclobber "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-6670">13.5 Redirection in C Shell: Capture Errors, Too? </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-14298"></A><ACLASS="indexterm"NAME="AUTOID-14301"></A><ACLASS="indexterm"NAME="AUTOID-14304"></A><ACLASS="indexterm"NAME="AUTOID-14308"></A>The <CODECLASS="literal">&gt;</CODE> (right angle bracket) operator redirects the standard output of aprocess to a file.It doesn't affect the standard error.If you're logged in and can see any messages written to standard error,that's okay:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>nroff -ms report.ms &gt; report.out &amp;</B></CODE>[1] 10316   ...<EMCLASS="emphasis">Later</EM>...nroff: can't open file /hoem/jpeek/report.data</PRE></BLOCKQUOTE></P><PCLASS="para">But if you log out and leave the job running, you'll never see those errors<ACLASS="indexterm"NAME="AUTOID-14318"></A>unless you use the <EMCLASS="emphasis">csh</EM> operator <CODECLASS="literal">&gt;&amp;</CODE>.It redirects both standard output and standard error to a file.For example:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch28_13.htm"TITLE="28.13 make Isn't Just for Programmers! ">make</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>make &gt;&amp; make.output &amp;</B></CODE>[1] 10329% <CODECLASS="userinput"><B>logout</B></CODE>   ...<EMCLASS="emphasis">Later</EM>...% <CODECLASS="userinput"><B>cat make.output</B></CODE>        cc -O -c random.c        cc -O -c output.c&quot;output.c&quot;, line 46: syntax error&quot;output.c&quot;, line 50: time_e undefined&quot;output.c&quot;, line 50: syntax error   ...</PRE></TD></TR></TABLE></P><PCLASS="para">You might also use the <CODECLASS="literal">&gt;&amp;</CODE> operator while you're logged in&nbsp;- and watchthe output file with<SPANCLASS="link"><EMCLASS="emphasis">tail -f</EM> (<ACLASS="linkend"HREF="ch25_16.htm"TITLE="How to Look at a File as It Grows ">25.16</A>)</SPAN>.If you don't want the errors mixed with other output, you can split themto two files; see article<ACLASS="xref"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-14336"></A>The C shell also has a pipe operator, <CODECLASS="literal">|&amp;</CODE>, that redirects bothstandard output and standard error.It's great for running a job in the background, or on another computer,and<SPANCLASS="link">mailing (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>any output to me:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>make |&amp; mailx -s &quot;'make bigprog' output&quot; jpeek@jpeek.com &amp;</B></CODE>[1] 29182 29183</PRE></BLOCKQUOTE></P><PCLASS="para">If I'd used plain <CODECLASS="literal">|</CODE> instead of <CODECLASS="literal">|&amp;</CODE>, any text on the standarderror wouldn't go into the mail message.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</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="ch13_04.htm"TITLE="13.4 Problems Piping to a Pager "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 13.4 Problems Piping to a Pager "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="ch13_06.htm"TITLE="13.6 Safe I/O Redirection with noclobber "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 13.6 Safe I/O Redirection with noclobber "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">13.4 Problems Piping to a Pager </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">13.6 Safe I/O Redirection with noclobber </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 + -