Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 452  / 2 Years ago, sun, february 27, 2022, 4:07:09

If I do this:


touch {1,2,3}.txt

I get


1.txt 2.txt 3.txt

But if I do this


touch {"File 1", "File 2"}.txt

I don't get expected 'File 1.txt' 'File 2.txt'. What is the proper approach in this case?


More From » bash

 Answers
5

Whitespace after the , causes the shell to parse your expression as two separate tokens, instead of as a brace expansion:


$ printf '%s
' {"File 1", "File 2"}.txt
{File 1,
File 2}.txt

You just need to remove the whitespace:


$ printf '%s
' {"File 1","File 2"}.txt
File 1.txt
File 2.txt

So


$ 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


[#608] Monday, February 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atetamme

Total Points: 11
Total Questions: 121
Total Answers: 109

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
atetamme questions
;