Linux shell directives such as-D,-F,-e are judged by :
File comparison Operators
-e filename true if filename exists [-e/var/log/syslog]
-D filename True if filename is a directory [-d/tmp/mydir]
-F filename True if filename is a regular file [-f/usr/bin/grep]
-L filename True if filename is a symbolic link [-l/usr/bin/grep]
-R filename True if filename is readable [-r/var/log/syslog]
-W filename if filename is writable, true [-w/var/mytmp.txt]
-X filename is true if filename is executable [-l/usr/bin/grep]
Filename1-nt filename2 If filename1 is newer than filename2, then true [/tmp/install/etc/services-nt/etc/services]
Filename1-ot filename2 If filename1 is older than filename2, then true [/boot/bzimage-ot Arch/i386/boot/bzimage]
String comparison operators (note the use of quotation marks, which is a good way to prevent whitespace from disturbing the code)
-Z String True if string length is zero [-Z ' $myvar ']
-N String if string length is nonzero, true [-n ' $myvar ']
string1= string2 If string1 is the same as string2, then true ["$myvar" = "One of the three"]
string1!= string2 If string1 differs from string2, true ["$myvar"! = "one, three"]
Arithmetic comparison operators
Num1-eq num2 equals [3-eq $mynum]
Num1-ne num2 Not equal to [3-ne $mynum]
Num1-lt num2 less than [3-lt $mynum]
Num1-le num2 less than or equal to [3-le $mynum]
NUM1-GT num2 greater than [3-GT $mynum]
Num1-ge num2 greater than or equal to [3-ge $mynum]
Reference: http://blog.csdn.net/sxzlc/article/details/7542603
Linux Shell Case statement:
The case statement is suitable for applications that require multiple branching.
The case Branch statement is formatted as follows:
Case $ variable name in
Mode 1)
Command sequence 1
;;
Mode 2)
Command Sequence 2
;;
*)
Sequence of commands executed by default ;;
Esac
The case statement has the following structural characteristics:
The case line end must be the word "in", and each pattern must be terminated with a closing parenthesis ")".
Double semicolon ";;" Indicates the end of the command sequence.
The matching pattern uses square brackets to denote a contiguous range, such as [0-9]; Use the vertical bar symbol "|" Represents or.
The Last "*)" represents the default mode, and when the variable is not matched using the preceding modes, "*" is executed
Sequence of commands.
For example:
1 Case " $" inch //Judge $2*.sh)//if it is a. sh file, then perform this one3# Source Shell Script forSpeed . 4 ( 5Trap-INT QUIT TSTP6scriptname=$1 7 Shift8 . $scriptname9 ) Ten ;; One*)//if it is not. SH then perform this default A "[email protected]" - ;; -Esac
Reference Source: http://blog.csdn.net/dreamtdp/article/details/8048720
Linux shell parameters:
$ $ represents the first parameter.
The $ $ represents the second argument.
$ $ represents a third parameter.
[email protected] represents all parameters, this is the way the array is represented by all parameters.
$# represents the number of parameters.
$* can also represent all the parameters.
Common statements for Linux shell scripts