check if a directory exists in a shell script. source - http://stackoverflow.com/questions/59838/check-if-a-directory-exists-in-a-shell-script
if [ -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY exists.
fi
if [ ! -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
fi