busybox/shell/brace.txt
<<
>>
Prefs
   1Brace Expansion
   2
   3Brace expansion is a mechanism by which arbitrary strings may be gener-
   4ated.   This  mechanism is similar to pathname expansion, but the file-
   5names generated need not exist.  Patterns to be brace expanded take the
   6form of an optional preamble, followed by either a series of comma-sep-
   7arated strings or a sequence expression between a pair of braces,  fol-
   8lowed  by  an  optional  postscript.   The preamble is prefixed to each
   9string contained within the braces, and the postscript is then appended
  10to each resulting string, expanding left to right.
  11
  12Brace  expansions  may  be nested.  The results of each expanded string
  13are not sorted;  left  to  right  order  is  preserved.   For  example,
  14a{d,c,b}e expands into `ade ace abe'.
  15
  16A  sequence  expression takes the form {x..y}, where x and y are either
  17integers or single characters.  When integers are supplied, the expres-
  18sion  expands  to each number between x and y, inclusive.  When charac-
  19ters are supplied, the expression expands  to  each  character  lexico-
  20graphically between x and y, inclusive.  Note that both x and y must be
  21of the same type.
  22
  23Brace expansion is performed before any other expansions, and any char-
  24acters  special to other expansions are preserved in the result.  It is
  25strictly textual.  Bash does not apply any syntactic interpretation  to
  26the context of the expansion or the text between the braces.
  27
  28A  correctly-formed  brace  expansion must contain unquoted opening and
  29closing braces, and at least one unquoted comma  or  a  valid  sequence
  30expression.   Any incorrectly formed brace expansion is left unchanged.
  31A { or , may be quoted with a backslash to prevent its being considered
  32part  of  a brace expression.  To avoid conflicts with parameter expan-
  33sion, the string ${ is not considered eligible for brace expansion.
  34
  35This construct is typically used as shorthand when the common prefix of
  36the strings to be generated is longer than in the above example:
  37
  38       mkdir /usr/local/src/bash/{old,new,dist,bugs}
  39or
  40       chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
  41
  42Brace  expansion  introduces  a  slight incompatibility with historical
  43versions of sh.  sh does not treat opening or closing braces  specially
  44when  they  appear as part of a word, and preserves them in the output.
  45Bash removes braces from words as a  consequence  of  brace  expansion.
  46For  example,  a word entered to sh as file{1,2} appears identically in
  47the output.  The same word is output as file1 file2 after expansion  by
  48bash.   If strict compatibility with sh is desired, start bash with the
  49+B option or disable brace expansion with the +B option to the set com-
  50mand
  51