On Fri, Jun 17, 2016 at 01:57:33PM -0700, dp...@realtruck.com wrote: > OPTS=(-q -avz --delete -e \'ssh -i /home/$currentuser/.ssh/id_rsa\' > --rsync-path=\'sudo rsync\')
You want: OTPS=(-q -avz --delete -e "ssh -i /home/$currentuser/.ssh/id_rsa" --rsync-path="sudo rsync") OPTS+=( whatever ) rsync "${OPTS[@]}" The entire point of using an array to hold arguments is that each array element expands to one argument (word). Each of the "-e" and "--rsync-path=" options expects its corresponding argument to be a single word. The array elements are not passed through an eval step. So you simply quote them the same way you would quote them if you were writing the rsync command without an array expansion step. Do note that the $currentuser variable must not contain any shell metacharacters (including spaces), because rsync itself will pass the arguments of -e and --rsync-path= through a shell evaluation step. Shell metacharacters will break at that point, and there is absolutely nothing you can do about it.