1 | initial version |
Here's an example of how to use brace expansion in a script using /bin/dash:
#!/bin/sh
# create directories using brace expansion
mkdir {test1,test2,test3}/{dir1,dir2}
# create files using brace expansion
touch {test1,test2,test3}/file{1..5}.txt
In this script, we're creating three directories with subdirectories within them using brace expansion (test1/dir1
, test1/dir2
, test2/dir1
, etc.). We're also creating files in each of these directories using brace expansion (file1.txt
, file2.txt
, etc.).
Note that in dash (which is a minimal shell), brace expansion is not enabled by default. To enable it, you can set the set -B
option at the beginning of your script.