Implementing code One,
Mypath= "/var/log/httpd/" myfile= "/var/log/httpd/access.log" # Here's the-x parameter to determine if $mypath exists and has executable permissions if [!-X ' $myPath]; Then mkdir "$myPath" fi# here the-d parameter to determine if $mypath exists if [!-D "$myPath"]; Then mkdir "$myPath" FI # Here's the-f parameter to determine if $myfile exists if [!-F "$myFile"]; Then touch "$myFile" fi# other parameters and-n,-n is to determine if a variable has a value if [!-n "$myVar"]; Then echo ' $myVar is empty ' exit 0fi # Two variables determine if equal if ["$var 1" = "$var 2"]; Then echo ' $var 1 eq $var 2 ' else echo ' $var 1 not EQ $var 2 ' fi
Implementation code Two,
#shell判断文件夹是否存在 #如果文件夹不存在, create a folder if [!-D "/myfolder"]; Then Mkdir/myfolderfi #shell判断文件 whether the directory exists or has permissions folder= "/var/www/" file= "/var/www/log" #-x parameter to determine $folder Whether it exists and has enforceable permissions if [!-X ' $folder]; Then mkdir the "$folder" FI #-D parameter to determine if the $folder exists if [!-D "$folder"]; Then mkdir the "$folder" FI #-F parameter to determine if $file exists if [!-F "$file"]; Then touch "$file" fi #-N to determine if a variable has a value if [!-n "$var"]; Then echo "$var is empty" Exit 0fi # Determine if two variables are equal if ["$var 1" = "$var 2"]; Then echo ' $var 1 eq $var 2 ' else echo ' $var 1 not EQ $var 2 ' fi-f and-e difference conditional Logic on files-a file Exists.-b file Exi STS and is a block special File.-c file exists and are a character special file.-d file exists and is a directory.-e file E Xists (just the same as-a).-F file exists and is a regular file.-g file exists and have its setgid (2) bit set.-g file Exis TS and have the same group ID as this process.-k file exists and have its sticky bit set.-l file exists and is a symbolic li Nk.-n string length is not zero.-o Named option is set ON.-o file exists and is owned by the user ID of this process.-p file exists and are a first in, first Out (FIFO) Special fi Le ornamed pipe.-r file exists and is readable by the current Process.-s file exists and have a size greater than zero.-s F Ile exists and is a socket.-t file descriptor number Fildes are open and associated with aterminal Device.-u file exists an D have its setuid (2) bit set.-w file exists and are writable by the current Process.-x file exists and are executable by the Current Process.-z string length is zero. The difference between-s or with-F is great!