1
2
3
4
5
6
|
<h1 class="subsection">Filename Expansion</h1> <p>After word splitting, unless the <samp>-f</samp> option has been set (see <a href="the-set-builtin">The Set Builtin</a>), Bash scans each word for the characters ‘<samp>*</samp>’, ‘<samp>?</samp>’, and ‘<samp>[</samp>’. If one of these characters appears, and is not quoted, then the word is regarded as a <var>pattern</var>, and replaced with an alphabetically sorted list of filenames matching the pattern (see <a href="pattern-matching">Pattern Matching</a>). If no matching filenames are found, and the shell option <code>nullglob</code> is disabled, the word is left unchanged. If the <code>nullglob</code> option is set, and no matches are found, the word is removed. If the <code>failglob</code> shell option is set, and no matches are found, an error message is printed and the command is not executed. If the shell option <code>nocaseglob</code> is enabled, the match is performed without regard to the case of alphabetic characters. </p> <p>When a pattern is used for filename expansion, the character ‘<samp>.</samp>’ at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option <code>dotglob</code> is set. In order to match the filenames ‘<samp>.</samp>’ and ‘<samp>..</samp>’, the pattern must begin with ‘<samp>.</samp>’ (for example, ‘<samp>.?</samp>’), even if <code>dotglob</code> is set. If the <code>globskipdots</code> shell option is enabled, the filenames ‘<samp>.</samp>’ and ‘<samp>..</samp>’ are never matched, even if the pattern begins with a ‘<samp>.</samp>’. When not matching filenames, the ‘<samp>.</samp>’ character is not treated specially. </p> <p>When matching a filename, the slash character must always be matched explicitly by a slash in the pattern, but in other matching contexts it can be matched by a special pattern character as described below (see <a href="pattern-matching">Pattern Matching</a>). </p> <p>See the description of <code>shopt</code> in <a href="the-shopt-builtin">The Shopt Builtin</a>, for a description of the <code>nocaseglob</code>, <code>nullglob</code>, <code>globskipdots</code>, <code>failglob</code>, and <code>dotglob</code> options. </p> <p>The <code>GLOBIGNORE</code> shell variable may be used to restrict the set of file names matching a pattern. If <code>GLOBIGNORE</code> is set, each matching file name that also matches one of the patterns in <code>GLOBIGNORE</code> is removed from the list of matches. If the <code>nocaseglob</code> option is set, the matching against the patterns in <code>GLOBIGNORE</code> is performed without regard to case. The filenames <samp>.</samp> and <samp>..</samp> are always ignored when <code>GLOBIGNORE</code> is set and not null. However, setting <code>GLOBIGNORE</code> to a non-null value has the effect of enabling the <code>dotglob</code> shell option, so all other filenames beginning with a ‘<samp>.</samp>’ will match. To get the old behavior of ignoring filenames beginning with a ‘<samp>.</samp>’, make ‘<samp>.*</samp>’ one of the patterns in <code>GLOBIGNORE</code>. The <code>dotglob</code> option is disabled when <code>GLOBIGNORE</code> is unset. </p> <ul class="section-toc"> <li><a href="pattern-matching" accesskey="1">Pattern Matching</a></li> </ul><div class="_attribution">
<p class="_attribution-p">
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br>
<a href="https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html</a>
</p>
</div>
|