problem with an IF statement

I need an IF statement that will compare the contents of the variable CX with the actual string "CP". ie. If the contents of $CX are NOT equal to the actual string "CP" then blah blah blah.

I have tried a number of things including the following.......

if [[ $CX != `echo CP` ]]; then

if [[ $CX != "CP" ]]; then

if [[ $CX != CP ]]; then

none of which seem to work

any suggestions ?

Which shell are you using?

Try using one set of brackets instead of two. All the ways you listed work fine in ksh...

CX="CR"

if [[ $CX != "CP" ]]; then
echo "not equal"
fi

if [ $CX != "CP" ]; then
echo "not equal"
fi

I would expect all 3 of your if statements to work in ksh although the first one is a poor choice.

My guess is that you have mis-diagnosed your problem. The if statements are working but the contents of your variable is not what you think.

Could the variable contain white space or unprintable characters? Put these in front of your if statement....

echo CX is ${#CX} characters in length
echo CX = $CX