"Linux" Bird's Linux Private Cuisine Basic Learning Chapter finishing (vii)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.