Shell Script Programming Learning notes-file test expressions

Source: Internet
Author: User
1.1 How to use a file to test an expression

When we need to process an object in programming, we need to test the object and only take action to meet the requirements. The benefit of this is to avoid program errors and to consume system resources without fear, which can be files, strings, numbers, and so on.

The following table is the common file operator

Special NOTE: These operators for [[]], [], test almost universal more operations can be viewed with the man test. The above table of the-e as long as there is a file on the line whether it is a file or directory, the popular saying is that some people find a girlfriend, is a woman on the line not picky eaters. hehe ~

1.2 File Test expression Example 1.2.1 Normal file (test file type)

1.2.2 Directory file (test file type)

1.2.3 Test File properties

1.2.4 Test Shell Variable Example

Special Example: If the variable is not double-quoted, the test result may be incorrect

1.3 Production environment system conditions test Content for NFS startup scripts

You can view the condition test content under/etc/init.d/rpcbind, which is not listed here. Learn the Shell programming multi-system script.

1.4 Most efficient examples of file judgments

When doing test judgment, it is not necessary to follow the previous method, directly using the latter to make Test judgment advantage more concise such as:

1.5 file test expression judgment condition after executing multiple command statement cases

Usage:

[Conditional]&&{

Command 1

Command 2

Command 3

.........

}

Example:

It is also possible to write multiple commands in a single line, separated by semicolons.

Shell Script Programming Learning notes-file test expressions

Related Article

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.