You can check the equality and inequality of two strings in bash by using if statement. “==” is used to check equality and “!= ” is used to check inequality of the strings. You can partially compare the values of two strings also in bash.
You should use the = operator for string comparison:
Sourcesystem="ABC"
if [ "$Sourcesystem" = "XYZ" ]; then
echo "Sourcesystem Matched"
else
echo "Sourcesystem is NOT Matched $Sourcesystem"
fi;
man test says that you use -z to match for empty strings.
-eq is used to compare integers. Use = instead.
eq is used to compare integers use equal '=' instead , example:
if [ 'AAA' = 'ABC' ];
then
echo "the same"
else
echo "not the same"
fi
good luck
I had this same problem, do this
if [ 'xyz' = 'abc' ]; then
echo "match"
fi
Notice the whitespace. It is important that you use a whitespace in this case after and before the = sign.
Check out "Other Comparison Operators".
-eq is the shell comparison operator for comparing integers. For comparing strings you need to use =.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With