Bash Shell Foundation II conditional judgment

Source: Internet
Author: User

if condition judgment; Then

Statment

Else

Statment

Fi

Or

if condition judgment; Then

Statment

Elif


Statment

Fi

Anti-quote: Returns the execution result of the command to the variable.

Set UserID

UserID = ' Id-u user1 '


command to end a script prematurely: exit: Exits the current process. is to exit the script

The end of any program has an execution status result and execution result. If get is the state result of the command

Exit to define the execution status results of the script.

Exit 0~255,0 is correct, 1~255 is error.


! Represent non, take counter action

if! grep ' ^work\> '/etc/passwd &>/dev/null; Then

echo "User does not exist"

Fi


Integer test:

-GT: Greater Than

-eq: Equals

-LT: Less than

-ne: Not equal to

-ge: greater than or equal to

-le: Less than or equal to


File test:

-E: Whether the file exists

-F: Test whether the file is a normal file

-D: Tests whether the specified path is a directory

-R: Tests whether the specified file is readable to the current user

-W: Tests whether the specified file is writable for the current user

-X: Tests whether the specified file is executable for the current user





This article is from the Linux learning blog, so be sure to keep this source http://884482.blog.51cto.com/874482/1697174

Bash Shell Foundation II conditional judgment

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.