linux系統中字符串比較語句


1、linux系統中字符串比較語句用來判斷字符串是否相等、或者字符串的代表的變量是否被賦值過

 = 表示字符串是否相同

[root@linuxprobe test]# a=xxx [root@linuxprobe test]# [ $a = "xxx" ] [root@linuxprobe test]# echo $?
0 [root@linuxprobe test]# [ $a = "yyy" ] [root@linuxprobe test]# echo $?
1

 

2、!=表示字符串是否不同

a=xxx [root@linuxprobe test]# [ $a != "xxx" ] [root@linuxprobe test]# echo $?
1 [root@linuxprobe test]# [ $a != "yyy" ] [root@linuxprobe test]# echo $?
0

 

3、-z 表示 字符串是否賦值了變量

[root@linuxprobe test]# echo $a xxx [root@linuxprobe test]# echo $b [root@linuxprobe test]# [ -z $a ] [root@linuxprobe test]# echo $?
1 [root@linuxprobe test]# [ -z $b ] [root@linuxprobe test]# echo $?
0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM