What are the common operators in Shell
This article mainly explains "what operators are commonly used in Shell". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what operators are commonly used in Shell.
I. arithmetic operation
The code is as follows:
+-* /%
II. Relational operation
The code is as follows:
< >> = 0, non-empty
-f formal documents
-w writable
-L symbolic connection
The-u file has a suid bit setting
-r readable
-x executable
For example, [- w tmp.txt] tests whether the file tmp.txt is writable
2. String testing
The code is as follows:
= two strings are equal
! = two strings are not equal
-z empty string
-n non-empty string
$VAR1='abc'
$VAR2='123'
$["$VAR1" = "$VAR2"]
$echo $?
one
3. Test value
The code is as follows:
-eq equals
-ne is not equal to
-gt is greater than
-lt less than
-ge greater than or equal to
-le less than or equal to
4. Extend the test symbol [[]] (())
The code is as follows:
# [[2 > 10]] # result error
# echo $?
0
# ((2 > 10)) the result is correct
# echo $?
0
# [["aa" = "aa"]]
# echo $?
0
# (("aa" = "aa")) # result error
# echo $?
one
Thank you for your reading, the above is the content of "what are the common operators of Shell". After the study of this article, I believe you have a deeper understanding of the problem of which operators are commonly used in Shell, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!