I’m having trouble writing up a simple perl script so I can sync two folders.
My code is:
my $string= "rsync -va ~/Dropbox/Music\ \(1\)/ ~/Music/Music/";
`$string`;
I also tried just using the line
`rsync -va /Dropbox/Music\ \(1\)/ ~/Music/Music/;`
Next I tried:
my @args=("bash", "-c","rsync -va ~/Dropbox/Music\ \(1\)/ ~/Music/Music/");
system(@args);`
I get the same error:
sh: -c: line 0: syntax error near unexpected token `(' each time
(yeah, those spaces and parens in the originating folder are a pain, but don’t yell at me, I didn’t create it….)
The problem is that the actual shell command you’re running is
because the all the backslashes are swallowed by Perl (since it, like Bash, uses backslash as a quoting/escape character). To avoid this, you need to either use single-quotes:
or else re-escape your backslashes: