zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    数据结构实验之栈四:括号匹配
    数据结构实验之栈三:后缀式求值
    8月7日学习
    8月6日学习
    8月5日学习
    8月4日学习
    周总结
    8月3日学习
    8月2日学习
    8月1日学习
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13829015.html
Copyright © 2011-2022 走看看