title: Why does this script not find directories with names ending in spaces
body: <p>I have the following script to recursively clean up directories when they no longer contain (any directories with) any .mp3 or .ogg files:</p>
  
  <pre><code>  set -u
    find -L $1 -depth -type d | while read dir
    do
      songList=`find -L "$dir" -type f \( -iname '*.ogg' -o -iname '*.mp3' \)` &amp;&amp; {
        if [[ -z "$songList" ]]
        then
          echo removing "$dir"
          rm -rf "$dir"
        fi
      }
    done
  </code></pre>
  
  <p>This works great, except that it fails in the case of directories that have a space as the last character of their name, in which case the second <code>find</code> fails, with the following feedback, if the script is invoked with . as its only argument, and a directory with the path <code>'./FOO/BAR BAZ '</code> (note the space at the end) exists:</p>
  
  <pre><code>find: `./FOO/BAR BAZ': No such file or directory
  </code></pre>
  
  <p>(Note the space that is now missing at the end, though other spaces are left intact.)</p>
  
  <p>I'm pretty sure it's a quoting thing, but every other way of quoting I've tried makes the behavior worse (i.e. more directories failing).</p>