Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Wrote a bash shell script that uses rsync to deploy files to live web server.

Right before executing, the script outputs the full command that the my shell script generates:

rsync --chmod="ug=rwx" -e="ssh" --filter="merge .deploy/filters" --dry-run --recursive -v --size-only "/var/www/vhosts/staging/" ""

This is being run inside my shell script like so:

local command=`getDeploymentCommand "$deploy_direction" "$mode"`
echo $command
echo `$command`

... and produces the following error:

rsync: Invalid argument passed to --chmod ("ug=rwx")

The chmod syntax looks correct to me. What's really weird is that the actual command copy-pasted into the shell and executed works fine. Why is this, and how can I make it work?

share|improve this question

Looking at the man page, the quotes aren't required, and are probably doing something unintended in the shell script versus pasted right into the command line. Try removing those quotes from your command.

The problem is that the shell allows variable interpolation inside double quotes. If you use single quotes, it doesn't allow interpolation, or you can escape-quote the quotes themselves to avoid interpolation.

share|improve this answer
The quotes are added automatically by my script for all parameter values. What about the filter parameter? That requires quotes to have merge in it, since it is followed by a space. – XedinUnknown Nov 1 '13 at 14:17
In the man page I'm looking at, the filter rule is surrounded by single quotes. This avoids interpolation of the string within the quotes, as opposed to double-quotes which allows interpolation. – John Nov 1 '13 at 14:19
In the man page I'm looking at, there is an example with double quotes. I see your point though, and here's an answer on the subject. Write a comprehensive answer using this new information, and I will mark it as accepted, since you were essentially right – XedinUnknown Nov 1 '13 at 14:22
I simply modified this answer instead of adding a second answer. – John Nov 1 '13 at 14:27
You didn't add the eval method, which, I believe, would be the best answer, since it allows to use the string as-is. – XedinUnknown Nov 1 '13 at 14:30

You must log in to answer this question.

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