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


Learn more >

Alibaba Cloud Free Trial


Learn more >

Contact Us

