title: How to create a bash script to delete accounts on mac
body: <p>I am creating a bash script to delete a user account on a mac.</p>
  
  <p>When I pull up terminal and type the commands</p>
  
  <pre><code>sudo dscl . delete /users/username
  </code></pre>
  
  <pre><code>sudo rm -rf /users/username
  </code></pre>
  
  <p>It is successful in deleting the desired account and removing the user files.</p>
  
  <p>However, when I create a bash script to do so...</p>
  
  <pre><code>#!/bin/bash
  sudo dscl . delete /users/username
  sudo rm -rf /users/username
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>delete: Invalid Path
  &lt;dscl_cmd&gt; DS Error: -14009 (eDSUnknownNodeName)
  </code></pre>
  
  <p>Very strange behavior I haven't been able to figure out, although it is likely a simple mistake.</p>
  
  <p>Edit: In my original script, I was doing looping among other things, but for this post I simplified the problem down to a couple of commands wrapped in a bash script.</p>
  
  <p>Thanks for any help.</p>