When do you use brace extension?

I realized that extension is an extension .
But I do not know where I use this.

When do you use it?
Please give me some handy examples.

Thanks.

+6
bash brace-expansion
source share
4 answers

The expression form for the range of the expansion of brackets is used instead of seq in the for loop:

 for i in {1..100} do something # 100 times done 
+4
source share

For example, back up all of your files in a directory:

 for i in * ; do cp "$i"{,.bak} done 
+2
source share

In bash, you use the bracket extension if you want to create a range, for example

for r in {0..100}

for r in {0..10..2} # in increments of 2

for z in {a..z}

Instead of using external commands like seq 0 100 . In addition, the list extension can be used to display file types, for example

for file in *.{txt,jpg} .

All files with txt and jpg extensions are listed in this list.

+2
source share

You use it when you want to match several options. For example.

 ls src/{Debug,Release}/*.o # List all .o files in the Debug and Release directories. 
0
source share

All Articles