First, if's basic syntax:
if [command];
Then
Statements that meet the criteria for execution
elif [command];
Then
Statements that meet the criteria for execution
Else
Statements that meet the criteria for execution
Fi
Second, File/folder (directory) Judgment
[-B file] True if file exists and is a block special file.
[-C file] True if file exists and is a word special.
[-D DIR] true if FILE exists and is a directory.
[-E File] True if file exists.
[-F file] True if file exists and is a normal file.
[-G file] True if file exists and Sgid has been set.
[-K file] True if file exists and the sticky bit has been set.
[-P file] If file exists and is a name pipe (f if O) is true.
[-R File] True if file exists and is readable.
[-S file] True if file exists and the size is not 0.
[-T FD] true if the file descriptor FD is open and points to a terminal.
[-u file] True if file exists and suid (set user ID) is set.
[-W file] True if file exists and is writable.
[-X file] True if file exists and is executable.
[-o file] True if file exists and is a valid user ID.
[-G file] True if file exists and is a valid user group.
[-L file] True if file exists and is a symbolic connection.
[-N file] If file exists and has been mod if IED since it was lastread true.
[-S file] True if file exists and is a socket.
[File1-nt FILE2] If FILE1 have been changed more Recentlythan FILE2, or if FILE1 exists and FILE2 does not is true.
[File1-ot FILE2] If FILE1 is older than FILE2, or FILE2 exists and FILE1 does not exist, it is true.
[File1-ef FILE2] True if FILE1 and FILE2 point to the same device and node number.
three, the string judgment[-Z string] True if the length of the string is zero, that is, if it is NULL, then NULL is true;
[-N string] True if the length of the string is nonzero, that is, the non-null is true;
[STRING1 = STRING2] True if two strings are the same;
[STRING1! = STRING2] True if the string is not the same;
[STRING1] True if the string is not empty, similar to-n
Four, numeric judgment int1-eq INT2 int1 and INT2 two number equals true, =
Int1-ne INT2 int1 and INT2 two numbers are true,<>
Int1-gt INT2 int1 greater than INT1 is true, Int1-ge INT2 &N Bsp;int1 greater than or equal to INT2 true, >=
int1-lt INT2 INT1 is less than INT2 true, <</div>
Int1-le INT2 INT1 less than or equal to INT2 true, <=
v. Complex logic judgment
-A with-O or! Non-
Exp1: If A>b and a
if ((a > B)) && ((a < C))
or
if [[$a > $b]]&& [ [$a < $c]
or
If [$a-gt $b-a $a-lt $c]
Exp2: If A>b or a
if ((a > B)) | | ((a < C))
or
If [[$a > $b] | | [$a < $c]
or
If [$a-gt $b-o $a-lt $c]
This article is from the "Kenasel" blog, make sure to keep this source http://kenasel.blog.51cto.com/10620829/1748860
Basic syntax and judgment of IF