Problems with spaces in filenames in scripts

Joseph Miller Joseph.Miller at
Fri Jan 18 07:41:13 EST 2002

I've got some (bash) shell scripts which I'm using to call rsync based
on command-line options passed to the script. The problem I'm having is
with spaces in the filenames/paths.

I can do:

rsync -rav --modify-window=2 --stats --partial --compress --timeout=30 
"localhost::module_name/dir/file with spaces.doc"  "/smb/dir/dir with

on the command line, or explicitly in a script, this works fine.

However.. when I invoke it from a script, like this:

opts='-rav --modify-window=2 --stats --partial --compress --timeout=30 
"localhost::module_name/dir/file with spaces.doc"  "/smb/dir/dir with
spaces/" '

rsync $opts

I get messages like:

rsync: getaddrinfo: "localhost 873: Name or service not known
rsync error: error in socket IO (code 10) at clientserver.c(85)

Or if I try just quoting the module/path part, ie
localhost::"module_name/dir/file with spaces.doc"

then I get:

@ERROR: Unknown module '"module_name'
rsync: connection unexpectedly closed (94 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(139)

Or if the destination path has spaces (and the server/module part
doesn't) then I get:

receiving file list ... done
mkstemp "/smb/dir/.dir.w5Kcqq failed

I've tried double quoting them as well ie:
'"localhost::module_name/dir"' as suggested in the FAQ-o-Matic, but this
still doesn't work..... The most perplexing part is that this only
occurs in scripts which pass the command-line options in a variable..

Has anyone else encountered this before? Had any luck? Help?

t h a n k s , 

j o s e p h  m i l l e r
i n f o r m a t i o n  s e r v i c e s
t r i m b l e  n a v i g a t i o n
n e w  z e a l a n d
j m i l l e r @ t r i m b l e . c o . n z
+ 6 4 - 3 - 9 6 3 5 5 8 1

More information about the rsync mailing list