Shell Script to check if Directory exist.
By admin • Jan 15th, 2009 • Category: ProgrammingTo check if a directory exists in a bash shell script you can use the following:
if [ -d "$DIRECTORY" ]; then
# Will enter here if $DIRECTORY exists
fi
Example:
if [ -d "/var/www/html/catur" ]; then
# Will enter here if $DIRECTORY exists
cp /var/www/html/pion/try.jpg /var/www/html/catur/try.jpg
fi
Or to check if a directory doesn’t exist:
if [ ! -d "$DIRECTORY" ]; then
# Will enter here if $DIRECTORY doesn’t exist
fiExample:
if [ ! -d "/var/www/html/catur" ]; then
# Will enter here if $DIRECTORY exists
mkdir /var/www/html/catur
fi
Home it’s usefull.
admin is
Email this author | All posts by admin


