title: How to pass source and destination paths to rsync as variables
body: <p>I'm writing a bash script to copy files from my local machine to a remote server using rsync. There is a space in the folder name "local folder" on my local machine; I don't know if this makes any difference.</p>
  
  <p>If I write it as plain text it works:</p>
  
  <pre><code>rsync -arv  --filter=":- .gitignore" /local\ folder/path/ user@123.4.5.6:~/
  </code></pre>
  
  <p>I want to put the source and destination paths as variables, but I can't get it to work. The first thing I tried is this:</p>
  
  <pre><code>SOURCE="/local\ folder/path/"
  DESTINATION="user@123.4.5.6:~/"
  rsync -arv  --filter=":- .gitignore" $SOURCE $DESTINATION
  </code></pre>
  
  <p>I see this error:</p>
  
  <pre><code>rsync: change_dir "/local folder/path//~" failed: No such file or directory (2)
  </code></pre>
  
  <p>It seems to be a) running source and destination together, and b) not seeing the server address.</p>
  
  <p>I've tried a number of variations, including braces:</p>
  
  <pre><code>rsync -arv  --filter=":- .gitignore" ${SOURCE} ${DESTINATION}
  </code></pre>
  
  <p>Using quotes:</p>
  
  <pre><code>rsync -arv  --filter=":- .gitignore" "${SOURCE}" "${DESTINATION}"
  </code></pre>
  
  <p>and putting the options into an array:</p>
  
  <pre><code>OPTIONS=( --protect-args -arv --filter=":- .gitignore")
  rsync "${OPTIONS[@]}" ${SOURCE} ${DESTINATION}
  </code></pre>
  
  <p>I have also tried this after checking it in <a href="https://www.shellcheck.net/" rel="nofollow noreferrer">https://www.shellcheck.net/</a></p>
  
  <pre><code>#!/bin/bash
  
  SOURCE="/folder name/path"
  DESTINATION=user@123.4.5.6:~/
  
  rsync -arv  --filter=":- .gitignore" "$SOURCE" $DESTINATION
  </code></pre>
  
  <p>and also:</p>
  
  <pre><code>#!/bin/bash
  
  SOURCE="/folder\ name/path"
  DESTINATION=user@123.4.5.6:~/
  
  rsync -arv  --filter=":- .gitignore" "$SOURCE" $DESTINATION
  </code></pre>
  
  <p>Each time I get the same error. What simple thing am I missing here? I've looked at various examples including:</p>
  
  <p><a href="https://www.redpill-linpro.com/sysadvent/2015/12/03/rsync-tricks.html" rel="nofollow noreferrer">https://www.redpill-linpro.com/sysadvent/2015/12/03/rsync-tricks.html</a>
  <a href="https://serverfault.com/questions/354112/rsync-and-bash-command-substitution">https://serverfault.com/questions/354112/rsync-and-bash-command-substitution</a></p>
  
  <p>The space isn't the issue, or at least not the only issue. I've tried using double quotes around my variable names as suggested <a href="https://stackoverflow.com/questions/10847127/bash-scripting-space-in-variable">here</a></p>
  
  <p>Thanks!</p>