1. Test function of the tests command.
Flags for testing:
(1) test for file type test [-EFDBCSPL] filename
-E: Whether the file name exists;
-F: Whether the file name is a file;
-D: Whether the file name is a directory;
-B: Whether the file name exists and is a block device;
-C: Whether the file name exists and is a character device;
-S: Whether the file name exists and is a socket file;
-P: Whether the file name exists and is a FIFO file;
-L: Whether the file name exists and is a connection file.
(2) Detection of file Permissions test [-r] FileName
-R: Detects if the file name exists and has a readable property;
-W: Detects if the file name exists and has a writable property;
-X: Detects if the file name exists and has an executable property;
-U: Detects if the file name exists and has the suid attribute;
-G: Detects if the file name exists and has the Sgid attribute;
-K: detects if the file name exists and has the sticky bit attribute;
-S: Detects if the file name exists and is not a blank file.
(3) Comparison of two files, such as Test file1-nt file2
-nt:newer than judge whether File1 is newer than file2;
-ot:older than judge whether File1 is older than file2;
-EF: Determine whether File1 and File2 are the same file name, can be used in judging hard link judgment, the main decision whether to point to the same inode.
(4) A comparison of two integers, such as test n1-eq N2
-eq: equal;
-ne: Not equal;
-gt:n1 greater than N2;
-lt:n1 less than N2;
-ge:n1 greater than or equal to N2;
-LE:N1 is less than or equal to N2.
(5) Decision string
Test-z string: Determines whether the string is empty;
Test-n string: Determines whether the string is non-null;
Test str1 = str2: Determines whether str1 equals str2;
Test str1! = str2: Determines whether str1 is not equal to str2.
(6) Multiple condition determination
-A: Two conditions at the same time, such as Test-r file-a-x file, if you determine whether the file has both readable and executable properties;
-O: Any condition, such as Test-r file-o-x file, determines if file has a readable or executable property;
!: Reverse state, such as test! -X file to determine if file does not have an executable property.
2. Use the judgment symbol [].
[] Instead of test, you need to be aware that the two ends of the brackets need to be separated by whitespace. For example, [-Z ' $HOME '] to determine if the HOME variable is empty.
3. Default variables for Shell script.
$: Script file name to execute;
$1,$2,$3 ...: nth parameter;
$#: The number of parameters to be followed;
[email protected]: represents all parameters, each variable is independent, separated by a space, enclosed in quotation marks;
$*: Represents "$1c$2c$3", C stands for delimiter, and the default is a space.
4. SH [-NVX] Script.sh:shell script tracking and debugging.
Parameters:
-N: Do not execute script, only check grammar problems;
-V: The contents of the script are output to the screen before executing the script;
-X: Displays the script content you are using to the screen.