3

I'm trying to back up files onto a server, but I'm having problems with files that have white spaces in the names.

I'm using this command in terminal:

FILES="testing/space\ in\ filename testing/and\ again"; rsync -v $FILES server::address

testing is the folder, with the two files being space in filename and and again.

When I run that, I get the following result:

rsync: link_stat "/home/user/testing/space\" failed: No such file or directory (2)
rsync: link_stat "/home/user/in\" failed: No such file or directory (2)
rsync: link_stat "/home/user/filename" failed: No such file or directory (2)
rsync: link_stat "/home/user/testing/and\" failed: No such file or directory (2)
rsync: link_stat "/home/user/again" failed: No such file or directory (2)

I've been looking into using the --protect-args option, but I haven't been able to get that working either.

1
  • Try quoting your $FILES variable: rsync -v "$FILES" (etc.)
    – Kusalananda
    Sep 30, 2011 at 20:48

1 Answer 1

1

You can temporarily change the IFS (internal field separator):

FILES="long filename with spaces
another one"
OLDIFS="$IFS"
IFS=$'\n'
rsync -v $FILES server::address
IFS="$OLDIFS" # restores default behaviour

Please note, that $'\n' is bashism. You might try this for other Posix shells:

IFS="
"

To process multiple files just separate them by your new IFS (in the above case a newline character). Instead of the newline character you might even use any characters you like.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .