To check if a directory exists in a bash shell script, use the following:
1 2 3 4 5 |
DIRECTORY="/some/path/dir" if [ -d "$DIRECTORY" ]; then # perform some action if $DIRECTORY exists. fi |
To check if a directory does not exists in a bash shell script, use the following:
1 2 3 |
if [ ! -d "$DIRECTORY" ]; then # perform some action if $DIRECTORY does not exists. fi |