Rsync in bash script not recognizing spaces

0

An excerpt from a bash script I'm using to backup some photos:

#!/bin/bash

FROM="/cygdrive/f/\"Trip to Austria\""
TO="/cygdrive/s/\"Trip to Austria\""

rsync -av $FROM $TO

When I print the final command from inside the script it prints properly, i.e.,

rsync -av /cygdrive/f/"Trip to Austria" /cygdrive/s/"Trip to Austria"

However, the command doesn't work when I run the script. The error I get relates to the spaces in the paths not being recognized.

rsync: link_stat "/cygdrive/f/Photos/"Trip" failed: No such file or directory (2)
rsync: link_stat "/home/User/to" failed: No such file or directory (2)
rsync: change_dir "/home/User/Austria"" failed: No such file or directory (2)

Strangely though, the command does work when I type it out in the Cygwin shell.

What gives?

Yony

Posted 2011-10-20T03:32:05.783

Reputation: 113

Answers

4

That's because bash is recognizing them first.

rsync -av "$FROM" "$TO"

Ignacio Vazquez-Abrams

Posted 2011-10-20T03:32:05.783

Reputation: 100 516