I'm writing a bash script to copy files from my local machine to a remote server using rsync. There is a space in the folder name "local folder" on my local machine; I don't know if this makes any difference.
If I write it as plain text it works:
rsync -arv --filter=":- .gitignore" /local\ folder/path/ user@123.4.5.6:~/
I want to put the source and destination paths as variables, but I can't get it to work. The first thing I tried is this:
SOURCE="/local\ folder/path/"
DESTINATION="user@123.4.5.6:~/"
rsync -arv --filter=":- .gitignore" $SOURCE $DESTINATION
I see this error:
rsync: change_dir "/local folder/path//~" failed: No such file or directory (2)
It seems to be a) running source and destination together, and b) not seeing the server address.
I've tried a number of variations, including braces:
rsync -arv --filter=":- .gitignore" ${SOURCE} ${DESTINATION}
Using quotes:
rsync -arv --filter=":- .gitignore" "${SOURCE}" "${DESTINATION}"
and putting the options into an array:
OPTIONS=( --protect-args -arv --filter=":- .gitignore")
rsync "${OPTIONS[@]}" ${SOURCE} ${DESTINATION}
I have also tried this after checking it in https://www.shellcheck.net/
#!/bin/bash
SOURCE="/folder name/path"
DESTINATION=user@123.4.5.6:~/
rsync -arv --filter=":- .gitignore" "$SOURCE" $DESTINATION
and also:
#!/bin/bash
SOURCE="/folder\ name/path"
DESTINATION=user@123.4.5.6:~/
rsync -arv --filter=":- .gitignore" "$SOURCE" $DESTINATION
Each time I get the same error. What simple thing am I missing here? I've looked at various examples including:
https://www.redpill-linpro.com/sysadvent/2015/12/03/rsync-tricks.html https://serverfault.com/questions/354112/rsync-and-bash-command-substitution
The space isn't the issue, or at least not the only issue. I've tried using double quotes around my variable names as suggested here
Thanks!