Shivam Tiwari
Shivam Tiwari

Reputation: 35

Shell Script not working correctly. What wrong am I doing here?

Screenshot depicting the issue

Please let me know what is error am I doing here. I am getting this output irrespective of the values of a and b variables.

Upvotes: 0

Views: 124

Answers (2)

Strictly speaking, == is used to compare strings. You'd like to use -eq to compare integer values. In the following example string comparison will fail even if integer value is the same:

    a=010
    b=10
    if [ $a == $b ] ; then
            echo "A == B"
    else
            echo "A <> B"
    fi

But if we change test operate to -eq

    a=010
    b=10
    if [ $a -eq $b ] ; then
            echo "A == B"
    else
            echo "A &lt;&gt; B"
    fi

Result will be A == B

Upvotes: 0

Antonio Petricca
Antonio Petricca

Reputation: 11070

You have to rewrite [ $a == $b] to [ $a == $b ].

Upvotes: 1

Related Questions