Shell string Expression Introduction-practice and enterprise case Scripting anatomy

Source: Internet
Author: User

Man test can see the string

 -n string              the  length of STRING is nonzero       STRING  equivalent to -n string       -z string               the length of string  is zero       STRING1 = STRING2               the strings are equal        STRING1 != STRING2               the strings are not equal        INTEGER1 -eq INTEGER2               integer1 is equal to integer2       integer1 -ge  Integer2              integer1 is  greater than or equal to integer

String test operators:

Common string test operators

-Z "string", if the string length is 0 true,-Z can be understood as zero

-N "string", if the string length is 0 true,-N can be understood as no zero

"String 1" = "String 2", if string 1 equals string 2 is true, you can use "= =" instead of "="

"String 1"! = "String 2", if string 1 is not equal to string 2 is true, but can not use "! = = "Replace"! =

Special attention:

1. The string test operation symbol in the above table must be enclosed in double quotation marks.

2. There must be spaces at both ends of the comparison symbol

3. String or string variable comparisons are double-quoted and then compared

4, string or string variable comparison, it is best to compare symbols at both ends have spaces.

Practice:

[[email protected] ~]# [ -n  "abc"  ]& &echo 1| | echo 01[[email protected] ~]# [ -n  ""  ]&&echo 1| | echo 0   0[[email protected] ~]# [ -z  "ABC"  ]&&echo  1| | echo 0 0[[email protected] ~]# [ ! -z  "ABC"  ]&&echo  1| | echo 01[[email protected] ~]# [ -n  "$test"  ]&&echo 1| | echo 01[[email protected] ~]# test= "Oldboy" [[Email protected] ~]# [ -n   "Test"  ]&&echo 1| | echo 01[[email protected] ~]# [ -n  "$test"  ]&&echo 1| | echo 01[[email protected] ~]# [  "$test"  =  "Oldboy"  ]&&echo  1| | Echo 0        1 


This article is from the "Sandshell" blog, make sure to keep this source http://sandshell.blog.51cto.com/9055959/1964139

Shell string Expression Introduction-practice and enterprise case Scripting anatomy

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.