Bash – Specify pipe output position

bashlinuxpipe

I want to do stuff like this:

echo myserver:~/dir/2/ | rsync -r HERE /local/path/

I want the output redirected to a specified location in the command. The echo stuff goes "HERE". What's the easiest way to do this?

Best Answer

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/
Related Question