title: zip recursively each file in a dir, where the name of the file has spaces in it
body: <p>I am quite stuck; I need to compress the content of a folder, where I have multiple files (extension .dat). I went for shell scripting.</p>
  
  <p>So far I told myself that is not that hard: I just need to recursively read the content of the dir, get the name of the file and zip it, using the name of the file itself.</p>
  
  <p>This is what I wrote:</p>
  
  <pre><code>for i in *.dat; do zip $i".zip" $i; done
  </code></pre>
  
  <p>Now when I try it I get a weird behavior: each file is called like "12/23/2012 data102 test1.dat"; and when I run this sequence of commands; I see that zip instead of recognizing the whole file name, see each part of the string as single entity, causing the whole operation to fail.</p>
  
  <p>I told myself that I was doing something wrong, and that the i variable was wrong; so I have replaced echo, instead than the zip command (to see which one was the output of the i variable); and the $i output is the full name of the file, not part of it.</p>
  
  <p>I am totally clueless at this point about what is going on...if the variable i is read by zip it reads each single piece of the string, instead of the whole thing, while if I use echo to see the content of that variable it gets the correct output.</p>
  
  <p>Do I have to pass the value of the filename to zip in a different way? Since it is the content of a variable passed as parameter I was assuming that it won't matter if the string is one or has spaces in it, and I can't find in the man page the answer (if there is any in there).</p>
  
  <p>Anyone knows why do I get this behavior and how to fix it? Thanks! </p>