#!/bin/sh mypath= "/var/log/httpd/" myfile= "/var/log/httpd/access.log" #这里的-x parameter Judging $ Whether the MyPath exists and has enforceable permissions if [!-X ' $myPath]; then mkdir "$myPath" fi
#这里的-D parameter to determine if $mypath exists if [!-D "$myPath"]; then mkdir "$myPath" fi #这里的-F parameter to determine if $myfile exists if [! -F "$myFile"]; Then touch "$myFile" fi #其他参数还有 The-n,-n is to determine if a variable has a value if [!-n "$myVar"]; then echo "$myVar is Empty " exit 0 fi #两个变量判断是否相等 If [" $var 1 "=" $var 2 "]; then echo ' $var 1 eq $var 2 ' else
Echo ' $var 1 not EQ $var 2 ' fi
The difference between-F and-E
Conditional Logic on Files
-A file exists.
-B file exists and is a block special file.
-c file exists and is a character special file.
-D file exists and is a directory.
-e file exists (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 exists 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 link.
-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 is a first in, first Out (FIFO) special file or
Named pipe.
-R file exists and is readable by the current process.
-S file exists and has a size greater than zero.
-s file exists and is a socket.
-T file descriptor number Fildes is open and associated with a
Terminal device.
-U file exists and have its setuid (2) bit set.
-W file exists and is writable by the current process.
-X file exists and is executable by the current process.
-Z string length is zero.
is the difference with-s or with-f this is very big!
Shell determines whether a file or folder exists