up vote 1 down vote favorite
share [g+] share [fb]

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.

link|improve this question
feedback

3 Answers

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>.

link|improve this answer
feedback

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
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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