I'm trying to create a simple wrapper shell script for rsync. When I send file names to my script, rsync can never seem to identify the correct location. The file names have spaces in them. I've tried a dozen different variations using quotes, double quotes, backslashed quotes, and using the rsync -s --protect-args flag. I'm finally out of ideas. Here is a simplified version of my script.
#!/bin/bash # Example usage: # pull.sh "file 1" "file 2" LOCATION="/media/WD100" all_files="" for file in "$@"; do all_files="$all_files:\"$LOCATION/$file\" " done # Pull the given files from homeserver to my current directory. rsync --progress --inplace --append-verify -ave ssh username@homeserver"$all_files" .
Should I be writing this differently? How do make this script work?
I changed my script to try to reflect Chazelas's answer, but it still seems not to work. Here is my new code:
#!/bin/bash # Example usage: # pull.sh "file 1" "file 2" LOCATION="/media/WD100" all_files="" for file in "$@"; do all_files="$all_files\"$LOCATION/$file\" " done rsync --progress --inplace --append-verify -0 --files-from=<(printf '%s\0' "$all_files") -ave ssh username@homeserver: .
Running it gives me the standard "usage" output, with this error at the end.
rsync error: syntax or usage error (code 1) at options.c(1657) [server=3.0.9] rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: error in rsync protocol data stream (code 12) at io.c(605) [Receiver=3.0.9]