tags:

views:

29

answers:

1

Code:

HOST=localhost
PORT=1234
RSYNCCMD="rsync -avP -e \"ssh -p $PORT\""

${(z)RSYNCCMD} root@$HOST:"\"/foo\"" /bar

Output:

rsync: Failed to exec ssh -p 1234: No such file or directory (2)
...

If I enter the same thing (rsync -avP -e "ssh -p 1234" ...) directly into the console, it works.

How do I fix it?

+1  A: 

using ${(Q)${(z)RSYNCCMD}} might work for you (instead of ${(z)RSYNCCMD})

(${(z)RSYNCCMD} seems to be expanded to rsync -avP -e \"ssh\ -p\ 1234\", (Q) does an additional unquoting magic)

mykhal
What are your options? That does not happen in my case.
ZyX
Understood. Yes, your answer should work, but topic starter may also consider using `eval ${(z)RSYNCCMD} ...`.
ZyX
`eval` has other problems, basically that I have to quote all of the rest. But the solution with `(Q)` works fine, thanks.
Albert