String comparison in if statement

Hi

Just trying to compare the following variables as a condition in an 'if' statement.

ZERODATA="unidentified 0 b (0%)"
DATA=`sed -n "${dln} p" mpck2.out`

...

if [ "$DATA" != "$ZERODATA" ]
then
...

The problem I'm getting is that the condition always comes out true and doesn't appear to compare them properly. If I use the 'ne' operator I get an error.

(All I actually want to know is if the string DATA contains the substring '0 b (0%)' and use that in the 'if' statement but I just want to get the match for now to simplify the problem.)

Is anyone able to tell me why these would not compare correctly?

Put a 'set -x' in the script so that you can see exactly what is being compared with what.

Jerry

if echo "$DATA" | fgrep '0 b (0%)' >/dev/null 2>&1; then
   echo "String matched."
...
fi

That may do what you are wanting. If DATA not too long/irregular the following might
be better...

if expr "$DATA" : '.*0 b (0%)' >/dev/null; then
    echo "String matched"
...
fi
case $DATA in
     *"0 b (0%)"*) echo YES ;;
     * ) echo NO ;;
esac

:b: That did the job nicely, heres how I applied it:

case $DATA in
     *"0 b (0%)"*)  ;;
     * )
echo $FILE
echo $DATA ;;
esac

Thanks again

I'd have used printf to avoid potential problems with echo:

case $DATA in
     *"0 b (0%)"*)  ;;
     * ) printf "%s\n%s\n" "$FILE" "$DATA" ;;
esac