Brace expansion
25 novembre 2008, 16:17 Open Source , Shell , System , Tips & Tricks November 25, 2008, 16:17
Here I respond to a request for help I received last week and so far I have not had time to respond.
I am asked for advice on a bash script that processes a set of directories and creates other temporarily in / tmp.
Without going into details of the case, to automatically generate lists or arrays directory comes in handy to brace expansion.
This is a special mechanism with which to bash you can generate arbitrary lists of names of files or directories.
In this sense it is similar to pathname expansion, although the latter is bound to the existence of files and / or the directory in question, while with coal expansion this limit is not expected.
The syntax is very simple and brace expansion expected to be listed in braces string that will be replaced in the same position within the main string, thereby generating variants that we need. As always, an example is worth a thousand explanations:
to {b, c, d} and
expands into:
- abe
- ace
- Hades
The brace expansion has priority over all other needs expansion and containing the opening and closing braces, and at least one separator (comma).
Here is the missing line of code to the script above:
/bin/mkdir /tmp/{dir_main,dir_all,dir_tmp_1,dir_tmp_2,dir_tmp_3}














