Compare a string using sh shell Compare a string using sh shell unix unix

Compare a string using sh shell


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