Shell common operator Summary _linux shell

Source: Internet
Author: User

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

Copy Code code 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
Copy Code code 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 $?
1

3. Test values
Copy Code code 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 [[]] (())
Copy Code code as follows:

# [[2 > 10]] # result error
# echo $?
0
# ((2 >10)) The result is correct
# echo $?
0
# [[[' AA ' = ' AA ']]
# echo $?
0
# ("AA" = "AA") #结果错误
# echo $?
1

Iv. Conclusion

    Compare numbers, using (())
    other tests using [[]]
    mixed tests containing numeric comparisons, using standard syntax

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.