In Linux BASH shell, you can use curly brace {} to represent a set of possible values in an array. For example,
1 | touch abc{1,2,3,4} |
touch abc{1,2,3,4}
This will be equivalent to four command as follows and as a result, 4 files will be generated.
1 2 3 4 | touch abc1 touch abc2 touch abc3 touch abc4 |
touch abc1 touch abc2 touch abc3 touch abc4
Please note that there should not be spaces inside the curly braces. For example,
1 2 | ~$ echo abc{1, 2, 3, 4} abc{1, 2, 3, 4} |
~$ echo abc{1, 2, 3, 4} abc{1, 2, 3, 4}
However,
1 2 | ~$ echo abc{" 1"," 2"," 3"," 4"} abc 1 abc 2 abc 3 abc 4 |
~$ echo abc{" 1"," 2"," 3"," 4"} abc 1 abc 2 abc 3 abc 4
This is useful, if you want to make several folders under a specific directory, you can use this elegant solution:
1 | mkdir /some/dir/{a,b,c,d} |
mkdir /some/dir/{a,b,c,d}
This will create four commands as:
1 2 3 4 | mkdir /some/dir/a mkdir /some/dir/b mkdir /some/dir/c mkdir /some/dir/d |
mkdir /some/dir/a mkdir /some/dir/b mkdir /some/dir/c mkdir /some/dir/d
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
201 wordsloading...
Last Post: PHP Script to Test Crontab
Next Post: CloudFlare supports SSL