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

📄 ch15_04.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 15] 15.4 What if a Wildcard Doesn't Match? </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:37:23Z"><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="ch15_01.htm"TITLE="15. Wildcards"><LINKREL="prev"HREF="ch15_03.htm"TITLE="15.3 Adding { } Operators to Korn (and Bourne) Shells "><LINKREL="next"HREF="ch15_05.htm"TITLE='15.5 Matching All "Dot Files&quot; with Wildcards'></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="ch15_03.htm"TITLE="15.3 Adding { } Operators to Korn (and Bourne) Shells "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 15.3 Adding { } Operators to Korn (and Bourne) Shells "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 15<BR>Wildcards</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch15_05.htm"TITLE='15.5 Matching All "Dot Files&quot; with Wildcards'><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT='Next: 15.5 Matching All "Dot Files&quot; with Wildcards'BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0019">15.4 What if a Wildcard Doesn't Match? </A></H2><PCLASS="para">I ran into a strange situation the other day. I was compiling aprogram that was<SPANCLASS="link">core dumping (<ACLASS="linkend"HREF="glossary.htm#UPT-ART-1010"TITLE="Glossary">52.9</A>)</SPAN>.At some point, I decided to delete theobject files and the <EMCLASS="emphasis">core</EM> file, and start over, so I gave the command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>rm *.o core</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">It works as expected most of the time, <EMCLASS="emphasis">except when</EM> no object filesexist. (I don't remember why I did this, but it was probably by using<SPANCLASS="link"><CODECLASS="literal">!!</CODE> (<ACLASS="linkend"HREF="ch11_07.htm"TITLE="History Substitutions ">11.7</A>)</SPAN>when I knew there weren't any <EMCLASS="emphasis">.o</EM>'s around.) In this case,<ACLASS="indexterm"NAME="AUTOID-16287"></A><ACLASS="indexterm"NAME="AUTOID-16289"></A>you get <CODECLASS="literal">No match</CODE>, and the <EMCLASS="emphasis">core</EM> file is <EMCLASS="emphasis">not</EM> deleted.</P><PCLASS="para">It turns out, for C shell users, that if none of the wildcards can beexpanded, you get a <CODECLASS="literal">No match</CODE> error. It doesn't matter that there'sa perfectly good match for other name(s).That's because, when <EMCLASS="emphasis">csh</EM> can't match a wildcard, it aborts and prints anerror&nbsp;- it won't run the command.If you create one <EMCLASS="emphasis">.o</EM> file orremove the <CODECLASS="literal">*.o</CODE> from the command line, <EMCLASS="emphasis">core</EM> will disappear happily.</P><PCLASS="para">On the other hand, if the Bourne shell can't match a wildcard,it just passes the unmatched wildcard and other filenames:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">*.o core</PRE></BLOCKQUOTE></P><PCLASS="para">to the command (in this case, to <EMCLASS="emphasis">rm</EM>) and lets the commanddecide what to do with it.So, with Bourne shell, what happens will depend on what your commanddoes when it sees the literal characters <CODECLASS="literal">*.o</CODE>.</P><PCLASS="para">You can make <EMCLASS="emphasis">csh</EM> act a lot like <EMCLASS="emphasis">sh</EM> by using:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">set nonomatch</PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN>, <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="ch15_03.htm"TITLE="15.3 Adding { } Operators to Korn (and Bourne) Shells "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 15.3 Adding { } Operators to Korn (and Bourne) Shells "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="ch15_05.htm"TITLE='15.5 Matching All "Dot Files&quot; with Wildcards'><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT='Next: 15.5 Matching All "Dot Files&quot; with Wildcards'BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">15.3 Adding { } Operators to Korn (and Bourne) Shells </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">15.5 Matching All "Dot Files&quot; with Wildcards</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 + -