?? _chapter 8.htm
字號:
<colgroup span="2" align="left">
</colgroup>
<tr>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Metacharacter</span> </th>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Meaning</span> </th>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">\</span>
</td>
<td class="docTableCell" vAlign="top">Literally interprets the following
character. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">&</span>
</td>
<td class="docTableCell" vAlign="top">Processes in the background. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">;</span>
</td>
<td class="docTableCell" vAlign="top">Separates commands. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">$</span>
</td>
<td class="docTableCell" vAlign="top">Substitutes variables. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">?</span>
</td>
<td class="docTableCell" vAlign="top">Matches for a single character. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">[abc]</span>
</td>
<td class="docTableCell" vAlign="top">Matches for one character from a set
of characters. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">[!abc]</span>
</td>
<td class="docTableCell" vAlign="top">Matches for one character
<span class="docEmphasis">not</span> from the set of characters. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">*</span>
</td>
<td class="docTableCell" vAlign="top">Matches for zero or more characters.
</td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">(cmds)</span>
</td>
<td class="docTableCell" vAlign="top">Executes commands in a subshell. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">{cmds}</span>
</td>
<td class="docTableCell" vAlign="top">Executes commands in current shell.
</td>
</tr>
</table>
<h4 class="docSection2Title" id="ch08lev2sec4">8.1.4 Filename Substitution</h4>
<p class="docText">When evaluating the command line, the shell uses
metacharacters to abbreviate filenames or pathnames that match a certain set of
characters. The filename substitution metacharacters listed in
<a class="docLink" href="#ch08table02">Table 8.2</a> are expanded into an
alphabetically listed set of filenames. The process of expanding the
metacharacter into filenames is also called <span class="docEmphasis">filename
substitution,</span> or <span class="docEmphasis">globbing.</span> If a
metacharacter is used and there is no filename that matches it, the shell treats
the metacharacter as a literal character.</p>
<table cellSpacing="0" cellPadding="1" width="100%" border="1">
<caption>
<h5 id="ch08table02" class="docTableTitle">Table 8.2. Shell Metacharacters and Filename
Substitution</h5>
</caption>
<colgroup span="2" align="left">
</colgroup>
<tr>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Metacharacter</span> </th>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Meaning</span> </th>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">*</span>
</td>
<td class="docTableCell" vAlign="top">Matches zero or more characters. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">?</span>
</td>
<td class="docTableCell" vAlign="top">Matches exactly one character. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">[abc]</span>
</td>
<td class="docTableCell" vAlign="top">Matches one character in the set
<span class="docEmphasis">a, b,</span> or <span class="docEmphasis">c.</span>
</td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">[a杬]</span>
</td>
<td class="docTableCell" vAlign="top">Matches one character in the range
from <span class="docEmphasis">a</span> to <span class="docEmphasis">z.</span>
</td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">[! a杬]</span>
</td>
<td class="docTableCell" vAlign="top">Matches one character
<span class="docEmphasis">not</span> in the range from
<span class="docEmphasis">a</span> to <span class="docEmphasis">z.</span>
</td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">\</span>
</td>
<td class="docTableCell" vAlign="top">Escapes or disables the metacharacter.
</td>
</tr>
</table>
<p class="docText"><b>The Asterisk.</b> The asterisk is a wildcard that matches
for zero or more of any characters in a filename.</p>
<h5 id="ch08list14" class="docExampleTitle">Example 8.14 </h5>
<pre>1 $ <span class="docEmphStrong">ls *</span>
<span class="docEmphasis">abc abc1 abc122 abc123 abc2 file1 file1.bak file2 file2.bak none</span>
<span class="docEmphasis">nonsense nobody nothing nowhere one</span>
2 $ <span class="docEmphStrong">ls *.bak</span>
<span class="docEmphasis">file1.bak file2.bak</span>
3 $ <span class="docEmphStrong">echo a*</span>
<span class="docEmphasis">ab abc1 abc122 abc123 abc2</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The asterisk expands to all of the files in the present
working directory. All of the files are passed as arguments to
<span class="docEmphasis">is</span> and displayed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">All files starting with zero or more characters and
ending with <span class="docEmphasis">.bak</span> are matched and listed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">All files starting with <span class="docEmphasis">a,</span>
followed by zero or more characters, are matched and passed as arguments
to the <span class="docEmphasis">echo</span> command.</span></li>
</ol>
</span></td>
</tr>
</table>
<p class="docText"><b>The Question Mark.</b> The question mark represents a
single character in a filename. When a filename contains one or more question
marks, the shell performs filename substitution by replacing the question mark
with the character it matches in the filename.</p>
<h5 id="ch08list15" class="docExampleTitle">Example 8.15 </h5>
<pre>1 $ <span class="docEmphStrong">ls</span>
<span class="docEmphasis">abc abc122 abc2 file1.bak file2.bak nonsense nothing one</span>
<span class="docEmphasis">abc1 abc123 file1 file2 none noone nowhere</span>
2 $ <span class="docEmphStrong">ls a?c?</span>
<span class="docEmphasis">abc1 abc2</span>
3 $ <span class="docEmphStrong">ls ??</span>
<span class="docEmphasis">?? not found</span>
4 $ <span class="docEmphStrong">echo abc???</span>
<span class="docEmphasis">abc122 abc123</span>
5 $ <span class="docEmphStrong">echo ??</span>
<span class="docEmphasis">??</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The files in the current directory are listed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">Filenames starting with <span class="docEmphasis">a,</span>
followed by a single character, followed by <span class="docEmphasis">c</span>
and a single character, are matched and listed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">Filenames containing exactly two characters are listed
if found. Since there are no two-character files, the question marks are
treated as a literal filename.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">Filenames starting with <span class="docEmphasis">abc</span>
and followed by exactly three characters are expanded and displayed by the
<span class="docEmphasis">echo</span> command.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">There are no files in the directory that contain
exactly two characters. The shell treats the question mark as a literal
question mark if it cannot find a match.</span></li>
</ol>
</span></td>
</tr>
</table>
<p class="docText"><b>The Square Brackets.</b> The brackets are used to match
filenames containing <span class="docEmphasis">one</span> character in a set or
range of characters.</p>
<h5 id="ch08list16" class="docExampleTitle">Example 8.16 </h5>
<pre>1 $ <span class="docEmphStrong">ls</span>
<span class="docEmphasis">abc abc122 abc2 file1.bak file2.bak nonsense nothing</span>
<span class="docEmphasis">one abc1 abc123 file1 file2 none noone nowhere</span>
2 $ <span class="docEmphStrong">ls abc[123]</span>
<span class="docEmphasis">abc1 abc2</span>
3 $ <span class="docEmphStrong">ls abc[1
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -