0

If this command:

touch Test{1..3}.txt

Allows me to create:

  • Test1.txt
  • Test2.txt
  • Test3.txt

What syntax would I need in order to batch create files containing a space in the file names?

For example:

  • Test 1.txt
  • Test 2.txt
  • Test 3.txt

Obviously, I can create files with spaces individually with no problem just by using quotation marks (see below) but, for some reason, I don't seem to be able to do the same thing when using brace expansion:

touch "Test 1.txt"

So far, I have tried the following but with no success:

touch "Test {1..3}.txt"

Is there a problem with my syntax or is this just not possible with brace expansion?

3

Quote the space:

touch Test" "{1..3}.txt
touch Test' '{1..3}.txt
touch "Test "{1..3}.txt
touch 'Test '{1..3}.txt
touch Test\ {1..3}.txt

All the above work correctly.

1
  • Thanks for showing all the possible solutions! Dec 13 '19 at 11:24
2

What you can try is something like:

touch Test\ {1..3}.txt

When other ways of escape char do not work back slash may work :)

1
  • 1
    It works!! I thought the solution would require quotation marks somewhere - very interesting!! Dec 13 '19 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.