diff options
Diffstat (limited to 'devdocs/bash/brace-expansion.html')
| -rw-r--r-- | devdocs/bash/brace-expansion.html | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/bash/brace-expansion.html b/devdocs/bash/brace-expansion.html new file mode 100644 index 00000000..241ec500 --- /dev/null +++ b/devdocs/bash/brace-expansion.html @@ -0,0 +1,16 @@ +<h1 class="subsection">Brace Expansion</h1> <p>Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to <em>filename expansion</em> (see <a href="filename-expansion">Filename Expansion</a>), but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional <var>preamble</var>, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional <var>postscript</var>. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right. </p> <p>Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example, </p> +<div class="example"> <pre class="example">bash$ echo a{d,c,b}e +ade ace abe +</pre> +</div> <p>A sequence expression takes the form <code>{<var>x</var>..<var>y</var>[..<var>incr</var>]}</code>, where <var>x</var> and <var>y</var> are either integers or letters, and <var>incr</var>, an optional increment, is an integer. When integers are supplied, the expression expands to each number between <var>x</var> and <var>y</var>, inclusive. Supplied integers may be prefixed with ‘<samp>0</samp>’ to force each term to have the same width. When either <var>x</var> or <var>y</var> begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary. When letters are supplied, the expression expands to each character lexicographically between <var>x</var> and <var>y</var>, inclusive, using the default C locale. Note that both <var>x</var> and <var>y</var> must be of the same type (integer or letter). When the increment is supplied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate. </p> <p>Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces. </p> <p>A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged. </p> <p>A { or ‘<samp>,</samp>’ may be quoted with a backslash to prevent its being considered part of a brace expression. To avoid conflicts with parameter expansion, the string ‘<samp>${</samp>’ is not considered eligible for brace expansion, and inhibits brace expansion until the closing ‘<samp>}</samp>’. </p> <p>This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example: </p> +<div class="example"> <pre class="example">mkdir /usr/local/src/bash/{old,new,dist,bugs} +</pre> +</div> <p>or </p> +<div class="example"> <pre class="example">chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} +</pre> +</div><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/Brace-Expansion.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html</a> + </p> +</div> |
