Create multiple space separated files using touch with curly brace extension
If I do this:
touch {1,2,3}.txtI get
1.txt 2.txt 3.txtBut if I do this
touch {"File 1", "File 2"}.txtI don't get expected 'File 1.txt' 'File 2.txt'. What is the proper approach in this case?
2 Answers
Whitespace after the , causes the shell to parse your expression as two separate tokens, instead of as a brace expansion:
$ printf '%s\n' {"File 1", "File 2"}.txt
{File 1,
File 2}.txtYou just need to remove the whitespace:
$ printf '%s\n' {"File 1","File 2"}.txt
File 1.txt
File 2.txtSo
$ touch {"File 1","File 2"}.txt
$ ls
'File 1.txt' 'File 2.txt'More compactly, you could also use touch "File "{1,2}.txt or touch File\ {1,2}.txt
Alternatively, also in bash, this can be done in a for loop like so:
for f in "fil 1" "file 2"; do touch "$f".txt
done