Problem comparing String using IF stmt

Hi frnds

Im facing an issues while trying to compare string using IF stmt, my code is:

chkMsgName=`Service Fee Detail`
 if [ $ctrlSrvcFeeMsgNm == $chkMsgName ]
     then
        if [ $ctrlSrvcFeeCnt == $cntWrdSrvcFee ]
        then 
            if [ $ctrlSrvcFeeLnItmCnt == $cntWrdSrvcFeeLnItm ]
            then
                echo "Valid File Ready for processing"
            fi
        fi
     fi

im getting the following error... :frowning:

parsingIfNew.ksh[65]: [: Fee: unknown operator

Please help me in sorting out this error.... Thanks in advance...

can you enclose the below variable to single or double quotes are try again...
chkMsgName=`Service Fee Detail`

I tried, but no use, again the same error... :frowning:

Please try the following (copy it => same sequence) :

chkMsgName="Service Fee Detail"
if [ $ctrlSrvcFeeMsgNm == $chkMsgName ]
then
	if [ $ctrlSrvcFeeCnt == $cntWrdSrvcFee ]
	then
		if [ $ctrlSrvcFeeLnItmCnt == $cntWrdSrvcFeeLnItm ]
		then
			echo "Valid File Ready for processing"
		fi
	fi
fi

Quote your variables:

chkMsgName="Service Fee Detail"
if [ "$ctrlSrvcFeeMsgNm" = "$chkMsgName" ]
then
   if [ "$ctrlSrvcFeeCnt" = "$cntWrdSrvcFee" ]
   then
      if [ "$ctrlSrvcFeeLnItmCnt" = "$cntWrdSrvcFeeLnItm" ]
      then
         echo "Valid File Ready for processing"
      fi
   fi
fi

Or, more concisely:

chkMsgName="Service Fee Detail"
if [ "$ctrlSrvcFeeMsgNm" = "$chkMsgName" ] &&
   [ "$ctrlSrvcFeeCnt" = "$cntWrdSrvcFee" ] &&
   [ "$ctrlSrvcFeeLnItmCnt" = "$cntWrdSrvcFeeLnItm" ]
then
   echo "Valid File Ready for processing"
fi

The error is because the variables are not quoted!

if [ $ctrlSrvcFeeMsgNm == $chkMsgName ]
then
...
fi

what if $ctrlSrvcFeeMsgNm is not populated?
runtime code will looks like

if [ == $chkMsgName ] # of course its an error
then
...
fi

So if you think this variable may or may not have value, then you should put it within double quotes.

if [ "$ctrlSrvcFeeMsgNm" == "$chkMsgName" ]
then
...
fi

Now runtime code will look like

if [ "" == "some_value" ]
 then
 ...
 fi
 

cfajohnson code will work!

regards,
Ahamed