Bash script using Rsync and heredoc for --files-from

Solved. Had to create an array and use “$i” as the source in the rsync arguments.

I would like to create a script that uses a heredoc as input to Rsync’s “–files-from” option but I cannot seem to get it figured out. Per the man page…

--files-from=FILE
Using  this  option allows you to specify the exact list of files to transfer (as read from the specified FILE or - for 
standard input).
It also tweaks the default behavior of rsync to make transferring just the specified files and directories easier:

A snippet of my script as follows:

# Getting include list
declare -a theList=(
    "$HOME/Documents/MyDocs"
    "$HOME/Downloads"
    "$HOME"/Library/Preferences/com.apple.dock.plist
    "$HOME"/Library/Preferences/com.apple.finder.plist
    "$HOME"/Library/Preferences/com.apple.menuextra.battery.plist
    "$HOME"/Library/Preferences/com.apple.menuextra.clock.plist
    "$HOME"/Library/Preferences/com.apple.sidebarlists.plist
)

/usr/bin/rsync -avzEh --files-from=${theList[@]} --exclude=".DS_Store" "$theDestination"/host-desktop

I’ve also tried:

# Include list
theList(){
    "$HOME/Documents/MyDocs"
    "$HOME/Downloads"
    "$HOME"/Library/Preferences/com.apple.dock.plist
    "$HOME"/Library/Preferences/com.apple.finder.plist
    "$HOME"/Library/Preferences/com.apple.menuextra.battery.plist
    "$HOME"/Library/Preferences/com.apple.menuextra.clock.plist
    "$HOME"/Library/Preferences/com.apple.sidebarlists.plist
)

As well as:

/usr/bin/rsync -avzEh /Users/me/Test --exclude=".DS_Store" --files-from=- <<-"EOF"
- "$HOME/Documents/MyDocs"
- "$HOME/Downloads"
- "$HOME"/Library/Preferences/com.apple.dock.plist
- "$HOME"/Library/Preferences/com.apple.finder.plist
- "$HOME"/Library/Preferences/com.apple.menuextra.battery.plist
- "$HOME"/Library/Preferences/com.apple.menuextra.clock.plist
- "$HOME"/Library/Preferences/com.apple.sidebarlists.plist
EOF

In an attempt to follow what I saw here.

using bash’s process substitution:

rsync ... --files-from=<(printf '%s\n' "${yourArray[@]}")

?

I’ve tried that and it doesn’t work. The output is error 1 which is syntax.

The –files-from option takes input a single file in the following format:

/path/to/file/
$HOME/foo/bar
/another/folder/file

So no need to use the bash shell array. Just use old good text file.

I have a Rsync script that does that but I wanted to find a way that doesn’t involve the use of an external file. And since it takes input from that single file there’s no reason it shouldn’t work by listing those files internally. I’ve been banging my head over this for about a week. I’ve posted on Reddit as well but can’t seem to get it figured out. The full script I currently use is here on Pastebin.

rsync --include=`printf "%s\n" ${theList[@]}`