Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rsync not working with variable containing a white space

Tags:

bash

shell

rsync

I cant get my rsync script to work if source or destination variable have a space in the folder name

#!/bin/bash
HOST="[email protected]"
source="/path/My Files/"
dest="/path/My Files2/"

rsync -avhP --delete "$HOST":"$source" "$dest"

the error i get is

receiving incremental file list
rsync: [sender] link_stat "/path/My" failed: No such file or directory (2)
rsync: [sender] change_dir "/root/Files" failed: No such file or directory (2)

Any help how to write this would be great

like image 534
gridrunner Avatar asked Nov 14 '25 09:11

gridrunner


1 Answers

Add option -s with current rsync version.

From man rsync:

-s, --protect-args: This option sends all filenames and most options to the remote rsync without allowing the remote shell to interpret them. This means that spaces are not split in names, and any non-wildcard special characters are not translated (such as ~, $, ;, &, etc.). Wildcards are expanded on the remote host by rsync (instead of the shell doing it).

like image 101
Cyrus Avatar answered Nov 17 '25 10:11

Cyrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!