4 ms·
Yup, same result. I've tried many small variations around the escaping of the double quotes, all with the same result. I haven't kept all of them but definitely
by liendolucas 3y ago
Yup, same result. I've tried many small variations around the escaping of the double quotes, all with the same result. I haven't kept all of them but definitely tried your approach.
- fragmede 3y agoOh it's the $(if [[ "${VALID_SSH}" == "yes" ]]; then echo "${REMOTE_SHELL}"; fi) \ Change that to $(if [[ "${VALID_SSH}" == "yes" ]]; then echo ${REMOTE_SHELL}; fi) \ and have REMOTE_SHELL="-e \"ssh -i '${ID_RSA}'\""
- liendolucas 3y agoNo, is not :-). With that approach the "-e" gets eaten, producing: rsync -av --no-perms --links "ssh -i id_rsa" . backup@redstar.local: But, you can re-insert it in the if with: $(if [[ "${VALID_SSH}" == "yes" ]]; then echo -e "\055e ${REMOTE_SHELL}"; fi) \ and removing the "-e" from the REMOTE_SHELL var. Then... Same error as before!
- deleted 3y ago[deleted]
- fragmede 3y agoClever. Stopping to think about this, I think setting REMOTE_SHELL="" when it doesn't want to get used, and then inserting it every time, instead of using the conditional rsync ... ${REMOTE_SHELL} ... should also work. If it's empty, then it won't add anything, but if there's something then it'll get passed in.
- liendolucas 3y agoUpdate, this seems to work: function backup { local SOURCE=$1 local DESTINATION=$2 local ID_RSA=$3 local VALID_SSH="yes" local RSYNC_OPTIONS=(-av --no-perms --links) if [[ "${VALID_SSH}" == "yes" ]]; then RSYNC_OPTIONS+=(-e "ssh -i ${ID_RSA}") fi rsync "${RSYNC_OPTIONS[@]}" "${SOURCE}" "${DESTINATION}" } I got lucky and found this information with an explanation at: https://www.mail-archive.com/search?l=bug-bash@gnu.org&q=subject:%22help+with+rsync+and+Missing+trailing%5C-%5C%22+in+remote%5C-shell+command.%22&o=newest&f=1 https://www.mail-archive.com/search?l=bug-bash@gnu.org&q=sub... So, is it a good advice to always use bash arrays to construct arbitrary options for commands?
- saurik 3y agoYes. I read this thread in shock and quite some level of dismay that you weren't using an array :(... I am very glad you came across the correct way to code that :).