Linux shell programming string compare syntax

后端 未结 4 981
小蘑菇
小蘑菇 2021-02-12 18:47

What is the difference between = and == to compare strings in Linux shell programming?

Maybe the following code works:

if [ \"$         


        
4条回答
  •  暖寄归人
    2021-02-12 19:33

    The single equal is correct

    string1 == string2

    string1 = string2

    True if the strings are equal. ‘=’ should be used with the test command for POSIX conformance

    NAME="rafael"
    USER="rafael"
    if [ "$NAME" = "$USER" ]; then
        echo "Hello"
    fi
    

提交回复
热议问题