rsync with remote filenames with spaces in from bash

Something that always annoys me with rsync is that due to executing a remote shell, any characters in the remote path name require double-escaping (once for this local shell, once for the remote one). For example

creates a remote folder called ‘my’ and puts the directory into that. The solution is to do something like:

But how to do this when you’re running from the shell eg iterating directories? One way would be to use a command like $(sed …) to handle the escaping, however you can do it purely in shell using two different types of quote. For example today I had to do:

Leave a Reply

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