#!/usr/bin/env bash

# Copy files/directories beginning with "EMAIL-" (where "EMAIL" is a
# student's email address) from directory given by $1 to the
# subdirectory of $2/EMAIL given by $3 with the "EMAIL-"
# portion removed from the file name.

debug=1

for file in $1/*-*; do
  filetail=${file##*/}
  email=${filetail%%-*}
  basename=${filetail#*-}
echo $2/$email/$3
  if [[ -e $2/$email/$3 ]]; then
     if (( $debug )); then echo "Doing: mv $file $2/$email/$3/$basename"; fi
     mv $file $2/$email/$3/$basename
  fi
done
