You are not logged in.

#1 2014-04-02 13:35:24

Osiris
Member
Registered: 2003-01-18
Posts: 157
Website

shell: Write variable to stdin of command

Hello,

probably very simple problem, but obviosly not for me:

rsync -av --exclude-from=- source target

reads the exclude list from stdin. How can I define this include list within my script and put in on stdin for rsync:

EXCLUDE="
~/Musik
~/.cache
"

rsync -av --exclude-from=- source target <<< "$EXCLUDE"

But that doesn't work...

Thanks!

Offline

#2 2014-04-02 13:58:01

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: shell: Write variable to stdin of command

rsync -av --exclude-from=- source target < <(echo "$EXCLUDE")

or

rsync -av --exclude-from=<(echo "$EXCLUDE") source target

I might try an EXCLUDE array and do

rsync -av --exclude-from=<(printf "%s\n" "${EXCLUDE[@]}") source target

I doubt any of this is 'best practice' though, and maybe this is an XYZ problem. Why are your excludes in a variable like that?


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#3 2014-04-02 14:44:48

Osiris
Member
Registered: 2003-01-18
Posts: 157
Website

Re: shell: Write variable to stdin of command

Why are your excludes in a variable like that?

In order to name multiple excludes for rsync you either have to use "--exclude=foo --exclude=bar --exclude=snafu ..." or --exclude-from=file. I deem the latter the most comfortable if I want to add or remove exclude patterns. Of course I could use a temp file too.

Offline

#4 2014-04-02 18:47:54

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,042

Re: shell: Write variable to stdin of command

EXCLUDE="
~/Musik
~/.cache
"

rsync -av --exclude-from=- source target <<EOF
$EXCLUDE
EOF

Offline

Board footer

Powered by FluxBB