Bash - Brace Expansion {} (Data Generation)

Bash Liste Des Attaques Ovh


Brace expansion is a mechanism by which arbitrary strings may be generated.

This mechanism is similar to pathname expansion, but the filenames generated need not exist.


Patterns to be brace expanded take the form of an optional preamble, followed by either:

  • a series of comma-separated strings
  • or a sequence expression between a pair of braces,

followed by an optional postscript.

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.

Series of comma-separated strings

echo 'Hello '{Foo,Bar}$' !\n'
Hello Foo !
Hello Bar !

Usage / Example

This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example:


  • with mkdir
mkdir /usr/local/src/bash/{old,new,dist,bugs}

Resulting in

mkdir /usr/local/src/bash/old /usr/local/src/bash/new /usr/local/src/bash/dist /usr/local/src/bash/bugs

chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

Resulting in:

chown root /usr/ucb/ex /usr/ucb/edit /usr/lib/ex?.?* /usr/lib/how_ex

Sequence Expression

Bash - Sequence



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.


Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example,

echo a{d,c,b}e

expands into:

ade ace abe


Brace expansion introduces a slight incompatibility with historical versions of sh. sh does not treat opening or closing braces specially when they appear as part of a word, and preserves them in the output.

Bash removes braces from words as a consequence of brace expansion.

For example, a word entered to sh as file{1,2} appears:

  • in sh identically in the output.
  • in bash: as file1 file2 after expansion.

If strict compatibility with sh is desired:

  • start bash with the +B option
  • or disable brace expansion with the +B option to the set command.

Discover More
Bash Liste Des Attaques Ovh
Bash - Expansion

This article is expansion in Bash. An expansion is the replacement of a special token in your code by the result of the expansion during code execution. It's performed on the command line after it has...
Bash Liste Des Attaques Ovh
Bash - Sequence

A sequence expression is a construct that creates sequence of numbers or characters. It's a brace expansion and takes the form where x and y are either: integers or single characters. A correctly-formed...
Bash Liste Des Attaques Ovh
Bash - Set (of Bash Options)

The set builtin command can be specify shell option. When options are specified, they set or unset shell attributes. Without options, the name and value of each shell variable are displayed in a...
Bash Liste Des Attaques Ovh
Bash - pathname expansion (Filename expansion)

pathname or filename expansion is an expansion (code replacement at runtime) that replaces globbing wildcard by pathname. pathfile name The asterisk character matches every filename in a given...
Card Puncher Data Processing
Shell - (Word|Token)

In a bash pipeline, the pipeline message is known as: the word the field This is a sequence of characters considered as a single unit by the shell. The first message is the standard input....
Shell - Sh (Bourne Shell)

sh is the original shell of Linux. is an extension but where there is some incompatibility between bash and sh. For example, see brace expansion. If strict compatibility with sh is desired: ...

Share this page:
Follow us:
Task Runner