Specify pipe output position

You can use xargs or exactly this requirement. You can use the -I as place-holder for the input received from the pipeline, do

echo "myserver:${HOME}/dir/2/" | xargs -I {} rsync -r "{}" /local/path/

(or) use ~ without double-quotes under which it does not expand to the HOME directory path.

echo myserver:~/dir/2/ | xargs -I {} rsync -r "{}" /local/path/

This

 rsync -r "$(echo myserver:~/dir/2/)" /local/path/

is the easiest way to do it.

Piping connects stdouts with stdins. Here you want the output to go to an argument, so you need something else than classical piping.

That something is command substitution ($()).


You may give rsync a list of files to download in a file or on standard input by using --files-from:

echo "dir/2/" | rsync --files-from=- -r user@server: /local/path/

The - makes rsync read from standard input. The server can't be given to rsync in this manner. There will only be a single connection made to the server and all files will be transferred over that connection.

If you use -a or --archive with --files-from then you need to explicitly add -r or --recursive if you want to recursion since that option, even though it's part of -a, is disabled when --files-from is used.

Tags:

Linux

Bash

Pipe