title: rm with ampersand in the end and without
body: <p>This is an interview question I was asked.             </p>
  
  <p>Say that you have a large script file, used for compiling and cleaning purposes. Also assume that you have folder named <code>folder</code> at the same directory of this file. In addition, in the end of this file you have the following code lines:           </p>
  
  <pre><code>clean:
      rm -r -f folder &amp;                    
  </code></pre>
  
  <p>when you try to clean a project, assume it works fine. However, if we remove the ampersand and write this:                      </p>
  
  <pre><code>clean:
      rm -r -f folder
  </code></pre>
  
  <p>then after you try to clean, you'll get the following error:               </p>
  
  <pre><code>rm: cannot remove 'folder': Directory not empty
  </code></pre>
  
  <p>But if you try to clean one more time, folder will be cleaned as desired.        </p>
  
  <p>I needed to find all possible reasons how could this happen. The only thing that I could think of is if we have some race between few threads running this script. Then I was asked- "what if only one thread run the code?"<br>
  I didn't see how could this problem happen with one thread- but it seems that I was mistaken and I don't know why. <strong>What other scenarios can cause the error above?</strong></p>
  
  <p>Edit: in the interview, I could also assume the following:<br>
  (1). There are no ampersands in other places at the script file, but the <code>rm</code> code line that I wrote.<br>
  (2). New files are not created in <code>folder</code> while performing rm</p>