Conditions test statement and Shell condition test statement in Shell

Source: Internet
Author: User

Conditions test statement and Shell condition test statement in Shell


Shell has conditional test statements. Generally, the test or [] commands are used to complete the test. They are conditional judgment statements if ~ The basis of the then statement, especially the [] command. The following describes some conditional test statements.


1. test command to implement conditional test

The test command is useful when detecting whether certain files exist in the system or related attributes.

The basic syntax is as follows:


The test command can also test the string:



The test command can also test the relationship between integers:



2. [] command to implement conditional Testing

Pay special attention to the use of the [] command in brackets to implement the conditional test function. Because brackets are useful in many places, such as wildcards and regular expressions. When [] is used for conditional testing, we must follow the following principles:

1) Each component in [] must be separated by a space key, for example, [□" $ HOME "□= □" $ MAIL" □]

2) the variables in brackets should be enclosed in double quotation marks;

3) constants in brackets are enclosed in single or double quotation marks.

[] Command to implement conditional testing is generally used for if ~ In the condition judgment Statement of then.


Refer:

Laruence's Linux private house dish


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.