Is it possible to get rsync to read a list of file to include from an array in the active script rather than a accompanying file?

## declare an array variable
declare -a files=("path" "path" "path")

rsync --files-from=${files[@]} source destination

Is there a better way to do this? I'd like to have just one script file to manage.

1 Answer 1


You can execute :

`rsync --files-from=<( printf "%s\n" "${files[@]}" ) source destination
  • <() wil open a pipe and fill it with the content of the inner command. It returns a file descriptor

  • printf "%s\n" "${files[@]}" echo each file name in a different line

  • Thanks @vera. Unfortunately I'm getting this:+ myFiles=(1\n 2\n 3\n) + rsync -avh --files-from=/dev/fd/63 /foo/ /bar/ ++ echo -e 1n 2n 3n building file list ... rsync: link_stat "/foo/1n 2n 3n" failed: No such file or directory (2) 0 files to consider
    – sansSpoon
    Sep 23, 2017 at 14:45
  • Ok, I see the problem: you can use printf instead of echo, then you do not have to add the trailing "\n". I edited the answer.
    – vera
    Sep 25, 2017 at 6:53
  • 1
    For me this doesn't work i got error with break-lines interpreted as #012. I had to use null character : rsync --files-from=<( printf "%s\0" "${files[@]}" ) --from0 source destination Oct 12, 2018 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .