Linux shell programming string compare syntax

后端 未结 4 1291
南方客
南方客 2021-02-12 19:07

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

Maybe the following code works:

if [ \"$         


        
4条回答
  •  借酒劲吻你
    2021-02-12 19:25

    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
    

提交回复
热议问题