title: Bash scripting, git and filenames with spaces
body: <p>I am trying to automate some of my interactions with git using bash scripts. To do so I have a script that will ssh and list all the repositories and then clone them. Part of the script is shown here </p>
  
  <pre><code>DIRS=`ssh $u "ls $p"`;
  for DIR in $DIRS; do
      echo "ssh://$u$p$DIR"
      echo "git clone ssh://$u$p$DIR";  
      git clone ssh://$u$p$DIR
  done
  </code></pre>
  
  <p>Example arguments are </p>
  
  <pre><code>-u user@host
  </code></pre>
  
  <p>and </p>
  
  <pre><code>-p /cygdrive/c/Documents\ and\ Settings/somePath
  </code></pre>
  
  <p>This work fine for filepaths with spaces in their names up until the git clone part where it throws an error about too many spaces. If I copy and pasted the part echoed by</p>
  
  <pre><code>echo "git clone ssh://$u$p$DIR";
  </code></pre>
  
  <p>then it clones just fine. I have tried to surround this in quotes but it throws an error</p>
  
  <pre><code>does not appear to be a git repository
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>Edit 1</strong> </p>
  
  <p>The errors when using <code>git clone "ssh://$u$p$DIR"</code> is</p>
  
  <pre><code>fatal: '/cygdrive/c/Documents\ and\ Settings/somePath/repo1' does not appear to be a git repository
  fatal: The remote end hung up unexpectedly
  </code></pre>