title: What is causing "Directory not empty" errors?
body: <p>I've written a script that is <em>mostly</em> working for me. However, the two <code>rmdir</code> commands at the end are sometimes returning <code>Directory not empty</code> errors. How do I beat this? I tried adding  <code>r</code> and then <code>-rf</code> which returned <code>Illegal option</code> errors. </p>
  
  <p>I'm a rookie, and I'd be grateful for any help. Here is the full shell script, which, again, is <em>mostly</em> working beautifully:</p>
  
  <pre><code>if [[ -z "${1}" ]]; then
    die "FolderName Required"
  fi
  
  newDirName="DirectoryName"
  newBaseDir="/Users/JSG/Desktop/DataFarm/$1/"
  /bin/mkdir -p $newBaseDir/{ProtectedOrig,Data}
  
  echo -n "---Data Folder Setup
  
  ---Data Introduction
  
  ---Data Audit/Manipulation
  
  ---Data Queries" &gt; $newBaseDir/Data/$1_DataJournal.txt
  
  ditto NewData/ NewDataCopy
  fab deploy_data_to_s3:data=*
  mv NewData/ $newBaseDir/ProtectedOrig/NewData
  mv NewDataCopy/ $newBaseDir/Data/NewDataCopy 
  mv $newBaseDir/Data/NewDataCopy/* $newBaseDir/Data/
  rmdir $newBaseDir/Data/NewDataCopy
  mv $newBaseDir/ProtectedOrig/NewData/* $newBaseDir/ProtectedOrig/
  rmdir $newBaseDir/ProtectedOrig/NewData
  chflags -R uchg $newBaseDir/ProtectedOrig/
  mkdir NewData
  </code></pre>
  
  <p>What am I missing? And thanks in advance! </p>