1. Use if in the script to determine whether the directory exists
#!/bin/bash if [ -d "c" ];then echo "directory c exists" else echo "Directory does not exist" fi
Recommendation: Linux Tutorial Column
2. Simple writing method
#!/bin/bash [ -d "c" ] && echo "directory c exists" # or [ -d "d" ] || echo "Directory d does not exist"
More judgment formats are as follows:
-e filename True if filename exists -d filename true if filename is a directory -f filename true if filename is a regular file -L filename true if filename is a symbolic link -r filename True if filename is readable -w filename true if filename is writable -x filename true if filename is executable -s filename True if file length is not 0 -h filename true if the file is a soft link