Shell Test command, Loop statement

Source: Internet
Author: User

Test command, Loop statement

Test command format:

Test condition

Usually, in the If-then-else statement, [] instead, that is, [condition]. Note that there are spaces on both sides of the square brackets.

Common commands:

-a two conditions at the same time, return truth

-O two conditions to set one, return the truth

-N ' followed by string

-Z to determine whether the string is 0, or null to return the true value

= Determines whether the left is equal to the right and, if equal, returns True

! = Determines whether the left is equal to the right and, if equal, returns false

-eq judge if the numbers are equal

-D determine file save and directory file

-E to determine if the file exists

-E to determine if a file exists and is a normal file

Logical judgment of If statement

: The result is always true

Determine user name and password, print login successful correctly

Vim a.sh

Judge what file # # # #一个判断是什么文件的脚本 b.sh

Query score Script score.sh

While loop

Break exits this layer loop

Continue to terminate this follow-up

While loop

If you run the script, the prompt permission is not enough, then we should chmod +x w.sh #脚本名 to give permissions to the script, in order to make a mistake, we should generally do the script after each build should be assigned permission operation, to avoid the situation we do not know that the permission file, the script does not run the situation

Vim w.sh

Judge Oldboy's age small script oldboy.sh

For loop

Add 30 users in bulk user.sh bulk Delete a user

Shell Test command, Loop statement

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.