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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。