网站开发技术

记点笔记、 学点技术 欢迎交流建站技术。本站关注lamp技术

您尚未登录。

#1 2014-12-23 09:59:49

admin
管理员

shell中的字符串比较

shell(linux 条件测试

示例

[root@ippbs ~]# test "this is test"
[root@ippbs ~]# echo $?
0 # 字符串不为空返回的都是真, 0 表示真


[root@ippbs ~]# test -n  "this is test"
[root@ippbs ~]# echo $?
0 # 这个也是真的


[root@ippbs ~]# test -z  "this is test"
[root@ippbs ~]# echo $?
1 # -z表示测试是否是空的。 这个是不是空的返回1
 

[root@ippbs ~]# test -n ""
[root@ippbs ~]# echo $?
1  # 如果是空的返回0


[root@ippbs ~]#
[root@ippbs ~]# test  "abc" = "abcd"
[root@ippbs ~]# echo $?
1  # 测试是否相等


[root@ippbs ~]# test "abc" != "abc"
[root@ippbs ~]# echo $?
1  # 测试不相等



ipbbs.net

离线

页脚

Powered by FluxBB