Command to check Directory Bash shell script?

In Bash shell script What command can be used to check if a directory does or does not exist?

	To check if a directory exists in a bash shell script you can use the following:

if [ -d “$DIRECTORY” ]; then
# Control will enter here if $DIRECTORY exists

	Or to check if a directory doesn't exist:

if [ ! -d “$DIRECTORY” ]; then
# Control will enter here if $DIRECTORY doesn’t exist

	However, as [Jon Ericson]( points out (thanks Jon), subsequent commands may not work as intended if you do not take into account that a symbolic link to a directory will also pass this check. E.g. running this:

if [ -d “$SYMLINK” ]; then
rmdir “$SYMLINK”

	Will produce the error message:

rmdir: failed to remove `symlink’: Not a directory

	So symbolic links may have to be treated differently, if subsequent commands expect directories:

if [ -d “$LINK_OR_DIR” ]; then
if [ -L “$LINK_OR_DIR” ]; then
# It is a symlink!
# Symbolic link specific commands go here
# It’s a directory!
# Directory command goes here
rmdir “$LINK_OR_DIR”