#!/bin/sh
# recursively delete empty directories

rmdir_empty() {
  # make default . explicit
  if [ -z "$1" ]; then
    set -- .
  fi

  # do the first level directories first
  for maxdepth_opt in "-maxdepth 1" ""; do
    find "$@" -depth -mindepth 1 $maxdepth_opt \
      -type d -empty -exec rmdir -v {} \;
  done
}

rmdir_empty "$@"