The shell judges whether the file, directory exists or has permissions
#!/bin/sh
myPath="/var/log/httpd/"
myFile="/var /log/httpd/access.log" #The
-x parameter here judges $myPath Whether it exists and has executable permission
if [ ! -x "$myPath"]; then
mkdir "$myPath"
fi #The
-d parameter here determines whether $myPath exists, ! -d means it does not exist
if [ ! -d " $myPath"]; then
mkdir "$myPath"
fi #The
-f parameter here determines whether $myFile exists
if [ ! -f "$myFile" ]; then
touch "$myFile"
fi #Other
parameters are -n,- n is to determine whether a variable has a value
if [ ! -n "$myVar" ]; then
echo "$myVar is empty"
exit 0
fi #Two
variables to determine whether they are equal
if [ "$var1" = " $var2" ]; then
echo '$var1 eq $var2'
else
echo '$var1 not eq $var2'
fi
Linux centOS shell to determine whether files and folders exist
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326371434&siteId=291194637
Ranking