Shell Process Control Statements

Source: Internet
Author: User

I. The existence and judgment of documents

-D to determine if the file exists and whether it is a directory file (the directory is true)

-E to determine if the file exists (exists as true)

-F to determine if the file exists and is a normal file (the normal file is true)

Second, the file permission to judge

-R to determine if the file exists and whether it has Read permission (Read permission is true)

-W to determine if the file exists and has Write permission (Write permission is true)

-X determines whether the file exists and has execute permission (with Execute permission true)

Third, integer judgment

The shell is a weakly typed language, and all of the default contents are strings, but the following comparison commands automatically convert the contents of both sides to numeric types, so no (())

-eq equal

-ne Not Equal

-ge greater than or equal to

-le less than or equal to

-GT Greater than

-lt less than

Iv. type of string

-Z string is empty, NULL returns True

-n string is not NULL, non-null return True

= = equals, equality is true (= can also be used to determine whether a string is equal, but is easily confused with assignment operations)

! = range, not equal to True

V. Multiple conditions of judgment

A is really true

-O One true is True

! Non -

VI. If statement

Single branch:

If [conditional judgment]

Then program

Fi

Dual Branch:

If[]

Then

echo "1"

Else

echo "2"

Fi

Multi-branch:

If[]

Then

echo "1"

Elif[]

Then

echo "2"

Else

echo "3"

Fi

Vii. Case Statements

Case $a in

"Yes")

echo "AA"

;;

"No")

echo "BB"

;;

*)

echo "CC"

;;

Esac

Viii. for Loop

For I in 1 2 3 4 5

Do

Echo $i

Done

For I in $ (cat a.txt)

Do

Echo $i

Done

S=0

For ((i=1;i<=100;i=i+1))

Do

s=$ (($s +$2))

Done

Nine, while loop

While [$i-le 100]

Do

.....

Done

While Read line

Do

......

Done < cat A.txt

Shell Process Control Statements

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.