Linux Process Control and variable comparison

Source: Internet
Author: User

Compare the size of two integers in a conditional expression with a comparison of two strings for equality, using a different operator.

(1) string comparison

-N STRING #字符串长度如果为非0则返回真

-Z STRING #字符串长度如果为0则返回真

STRING1 = STRING2 #两个字符串相同则返回真

STRING1! = STRING2 #两个字符串不相同则返回真


(2) Numerical comparison

where Arg1 and arg2 can be either a positive integer or a negative integer, but not a floating-point number.

Arg1-ne arg2 #arg1不等于arg2

Arg1-eq arg2 #arg1等于arg2

Arg1-lt arg2 #arg1小于arg2

Arg1-le arg2 #arg1小于等于arg2

ARG1-GT arg2 #arg1大于arg2

Arg1-ge arg2 #arg1大于等于arg2


Important

(1) The Shell's built-in test commands [and] need spaces on both sides.

(2) in the Test command [], use-eq to compare two strings for equality, compare the size of two integers (greater than, less than, equal to), and compare two strings for equality, using different operators.


Shell Process Control

    1. If,elif

(1) If condition

Then

Command

Fi

(2) If condition

Then

Command1

Else

Command2

Fi

(3) If condition

Then

Command1

Elif condition

Then

Command2

Elif condition

Command3

Fi


2.case

Case Word in

PATTERN1)

Command1

;;

PATTERN2)

Command2

;;

PATTERN3)

Command3

;;

*)

Command4

;;

Esac


3.while

While condition

Do

Command

Done


4.until

Until condition

Do

Command

Done


5.for

For name in words

Do

Command

Done


6.select

Select name in words

Do

Commands

Done


7.break


8.continue







Linux Process Control and variable comparison

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.