title: Bash script to delete aws s3 delete markers that have spaces in the key name
body: <p>I have found the following bash script online that will iterate over an s3 bucket and delete the object with delete markers:</p>
  
  <pre><code>$ sh delete_deletemarker.sh “my-bucket-name” “/path/to/a/directory”
  
  #!/bin/bash
  BUCKET=$1
  PREFIX=$2
  aws s3api list-object-versions --bucket $BUCKET --prefix $PREFIX --output text | 
   grep "DELETEMARKERS" | while read OBJECTS
     do
          KEY=$( echo $OBJECTS| awk '{print $3}')
          VERSION_ID=$( echo $OBJECTS | awk '{print $5}')
          echo $KEY
          echo $VERSION_ID
          aws s3api delete-object --bucket $BUCKET --key $KEY --version-id $VERSION_ID
      done
  </code></pre>
  
  <p>The only issue with this script, is that if the key ('filename') has a space or multiple spaces in the filename, the script will fail. For example a key with <em>'/cat/is_my_cat.jpg'</em> will work, but <em>'/cat/is my cat.jpg'</em> will not work. How would I change the above script to facilitate both keyname instances?</p>