Handling files/directories with spaces in `for’-loops

So I have one or the other file, that needs to be extracted to a directory. And why not name it as the archive itself .. Only problem with it is the handling of variables with bash …

Try it yourself, stuff some directories with a space in inside a variables, and use something like this:

And now take a look at the output of that ..

Means, the mkdir' created a directory for every entry in the ls‘ output that was separated by a space char … and I’ve no frickin clue on how to get that thing right … 😡

Update:
Thanks to Roy I know how one handles such things … 😳 It’s rather simple *g*

That should give you the desired effect ❗

2 thoughts to “Handling files/directories with spaces in `for’-loops”

  1. The way I learned to handle spaces in file names in shell loops is to use read like:

    ls -1 | while read i; do mkdir “${i/.archive/}”; done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.