3

I am sync-ing up a directory that has a bunch of documents in it. Users that input documents with all manner of weird characters in their file names. I need to sync up these files from one location on Linux to another. Many times only a single file needs to be updated. When the file name contains a single quote it croaks. I need to specify user@server for the destination, otherwise it works. For example:

rsync --rsh=ssh "zz/joe's change.txt" "/somedir/y/joe's change.txt"

works.

rsync --rsh=ssh "zz/joe's change.txt" user@server:"/somedir/y/"

also works.

But the form I wish to use:

rsync --rsh=ssh "zz/joe's change.txt" user@server:"/somedir/y/joe's change.txt"

fails with:

bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
rsync: connection unexpectedly closed (0 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(165)

I could use the second form (unless some nut puts a ' in the directory name), but really want to use the third form.

1

You probably need to escape that character. From bash man page

A non-quoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.

1

In this case, what finally worked for me was to use the --protect-args or -s argument, and then taking the whole thing under quotes as follows:

rsync -s --rsh=ssh "zz/joe's change.txt" "user@server:/somedir/y/joe's change.txt"

Note that even the remote server and user are also under the quotes.

0

Gleb put me on the right track. I had tried escaping inside the quotes (along with other variations on quoting and escaping the destination) and that did not work.

I have now gone back and found it will work by double escaping the destination:

rsync --rsh=ssh "zz/joe's change.txt" user@server:/somedir/y/joe\\\'s\\\ change.txt

or

rsync --rsh=ssh zz/joe\'s\ change.txt user@server:/somedir/y/joe\\\'s\\\ change.txt
0

Try:

rsync --rsh=ssh "zz/joe's change.txt" "user@server:/somedir/y/joe's change.txt"

The " is a signal to the shell and it may not work as part of an argument.

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.