title: Dealing with spaces in directory names in Bash
body: <p>Disclaimer: I am very new to Bash scripting (and Linux in general), so forgive me for a stupid question.</p>
  
  <p>A friend of mine gave me a script which makes a backup copy of certain files onto Dropbox. Here's the code in full:</p>
  
  <pre><code>#!/bin/sh
  DATE=`date +%Y-%m-%d`
  tarname='backup-'$DATE'.tar.gz'
  
  cd ~/
  directoriesToBack='.bashrc Desktop/School/ Desktop/Research\ Project'
  
  tar -X ~/Desktop/My\ Programs/scripts/crons/exclude.txt -zcvf $tarname $directoriesToBack
  
  mv $tarname ~/Dropbox 
  </code></pre>
  
  <p>The variable <code>directoriesToBack</code> obviously contains the directories to be copied. Exclude.txt is a text file of files which are not to be backed up.</p>
  
  <p>If I try to run this script, I get an error because of <code>Desktop/Research Project</code>: my computer looks for the directory <code>Desktop/Research</code> instead. I've tried to use double quotes instead of single quotes, and to replace <code>\</code> with an ordinary space, but these tries didn't work. Does anyone know how I can make a backup of a directory with spaces in its name?</p>