Shell script parsing 4 ---- branch statement (IF)

Source: Internet
Author: User

I. Condition statements

1,

If [expression]

Then

# Code block

Fi

2,

If [expression]

Then

# Code block

Else

# Code block

Fi

3,

If [expression]

Then

# Code block

Else if [expression] # Replace this field with Elif [expression]

Then

# Code block

Else

# Code block

Fi

Fi

Ii. Comparison of common condition statements

Comparison operation Integer Operation string operation

Same-eq =

Different-ne! =

Greater than-GT>

Less than-lt <

Less than or equal to-le

Greater than or equal to-Ge

Blank-z

Not empty-n

-E: determines whether the file already exists.

-F files are common files.

-S file size is not zero

-D file is a directory

-The R file can be read by the current user.

-W files can be written to the current user

-The X file can be executed on the current user.

For example:

#! /Bin/sh

Folder =/home

[-R "$ folder"] & Echo "can read $ folder" # "&" indicates that when the preceding is true, the following command is executed. It means "that.

[-F "$ folder"] | echo "this is not file" # "|" indicates that when the preceding value is false, the following command is executed. It means "otherwise.

 

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.