1

When referring to paths with spaces, e.g. Steve Jobs, I can either backslash escape, or surround with quotes, when the path is the local directory:

rsync Steve\ Jobs user@remote:/

or

rsync "Steve Jobs" user@remote:/

However, when Steve Jobs is the remote directory, surrounding with quotes is not sufficient. I also have to backslash escape the space:

rsync user@remote:/"Steve\ Jobs" .

Anyone know why this oddity happens?

If this is an artifact of SSH, why does SSH present this oddity?

2

rsync is passing the string within quotes to the remote machine. If you escape a space in quotes, then that backslash becomes part of the string (it is not eaten by your shell).

The rsync manual page refers to escaping:

If you need to transfer a filename that contains whitespace, you can either specify the --protect-args (-s) option, or you'll need to escape the whitespace in a way that the remote shell will understand. For instance:

CWrsync -av host:'file\ name\ with\ spaces' /dest

You can see how special characters are (or are not) eaten by the shell using a simple script like this:

#!/bin/sh
n=1
echo "$@"
for i in "$@"
do
    echo "$n:$i"
    n=`expr $n + 1`
done

calling that args:

$ args "xx\ yy"; args "xx yy"
xx\ yy
1:xx\ yy
xx yy
1:xx yy

Since rsync does not add quotes (unless asked, using -s), the spaces have to be handled specially when sent in as part of a shell command to the other machine.

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.