SUMMARY Re: Filenames with blanks

Ivan Kovalev ivan at wssource.com
Mon Aug 26 09:45:00 EST 2002


Problem:
use of
    rsync  -rxlupogtSvve ssh --delete $SRC:"$COM" $TARG
command where COM='`find '$src_dir'  -mtime -'$days' -type f `' for cases with
white space as a part of file name. List is parsed on white space instead of
on new line even if file names are quoted.
Best explanation: see message from Wayne below.
Suggested methods:
use zsh
alter IFS
push files instead of pull.

Tested working solution:
lst=`ssh $SRC find $src_dir  -mtime -$days -type f |while read f
do
     print -n \'$f\'' '
done `
[[ -n $lst ]] && rsync -rxlupogtSvve ssh  $SRC:"$lst" $TARG

Wayne Davison wrote:

> On Sat, 24 Aug 2002, Ivan kovalev wrote:
> > Still, I am not sure if I understand your suggestion. Looks like you are
> > saying: have output from COM like this:
> > /a/b/c d
> > /a/b/efg
> >
> > May be each line quoted.
>
> No.  Quotes are completely irrelevant since the shell is _only_ doing
> word-splitting, not arg parsing as the final step before sending the
> args to rsync.
>
> In other words:
>
>     `echo 'this is a command'`
>
> Turns into 4 separate args no matter what characters you add.  No amount
> of quoting, backslashing of spaces, or any other character additions
> will affect this because the only thing that backtick does is split the
> output on whitespace (using the contents of $IFS as the list of
> characters to use for the splitting).
>
> If you could change the IFS environment-variable value that the remote
> shell was using *when it was parsing the backticks* and make it have
> only a newline in it, that would cause the backticks to only split args
> on lines and not spaces, which is exactly what you want.  However, I see
> no easy way to get the remote shell into that mode (unless you can
> figure out some way to have the startup scripts conditionally set IFS
> based on the command that is about to run).
>
> In zsh and bash, the syntax $(...) is often a better way to say `...` in
> complex commands (since it's easily nestable).  Both shells let you say
> this (adding double quotes):
>
>     "$(ls -1)"
>
> This causes the whole output to be put into a single arg without any
> word-splitting.  However, we need the output split on newlines, so in
> zsh, this is trivial using the 'f' modifier (which is easier than saying
> "ps:\n:" -- i.e. split on newlines).  In other words, using this in zsh
> works perfectly:
>
>     ${(f)"$(ls -1)"}
>
> instead of this, which splits on too much whitespace:
>
>     `ls -1`
>
> I have no idea if bash has a way to selectively split args into multiple
> args (assuming you use bash).  This splitting has to be a shell-level
> construct because we have to turn output into args as the last step.
>
> If you feel like stepping up to what I consider to be the best shell
> around, feel free to give zsh 4.x a try.  It has the best commandline
> completion I've ever seen (though it's not on by default), and it has
> all the amenities that a bash user would expect and then some.  You'll
> find everything you need to check it out here:
>
>     http://zsh.sourceforge.net/
>
> If you're not that adventurous, maybe someone else who knows bash (or
> whatever shell you're using) could mention if this is possible.
>
> ..wayne..

--
Ivan Kovalev
Wall Street Source
120 Broadway, 27-th floor
New York, NY 10271
Pager: ikovalev at skytel.com, (888)688-5202
Phone: (212)479-1445
E-mail: ivan at wssource.com





More information about the rsync mailing list