Shell Common operator Summary

Source: Internet
Author: User
Tags arithmetic

This article mainly introduces the shell commonly used operator Summary, this article explained the arithmetic operator, the relational operator, the test operator and so on content, needs the friend to be possible to refer to under

First, the arithmetic operation

Copy code code as follows:

+ - * / %

Second, the relationship operation

Copy code code as follows:

< > >= <= = =!= && | |

Third, the test operation

Testing command: Test [] [[]] [()]

1. test file status

The code is as follows:

-D Directory

-B Block Equipment

-S file length > 0, Non-empty

-F Regular Documents

-W can write

-L Symbolic connection

-u file has suid bit settings

-R Readable

-X Executable

such as: [-w tmp.txt] test file tmp.txt is writable

2. String test

The code is as follows:

= Two strings equal

!= Two strings Not equal

-Z Empty string

-N Non-empty string

$ var1= ' abc '

$ Var2= ' 123 '

$ ["$VAR 1" = "$VAR 2"]

$ echo $?


3. Test values

The code is as follows:

-eq equals

-ne is not equal to

-GT Greater than

-lt less than

-ge is greater than or equal to

-le less than or equal

4. Expand test symbols [[]] (())

The code is as follows:

# [[2 > 10]] # result error

# echo $?


# ((2 >10)) The result is correct

# echo $?


# [[[' AA ' = ' AA ']]

# echo $?


# ("AA" = "AA") #结果错误

# echo $?


Iv. Conclusion

Compare numbers, use (())

Other tests use [[]]

Mixed tests that contain numeric comparisons, using standard syntax

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.