John Clarke wrote:

On Mon, Feb 16, 2004 at 10:13:28 +1100, David Kempe wrote:

#if (( "ERRORNUM" >= 1 )) if [ "$ERRORNUM" != 0 ]


!= is a string operator. You want to do a numeric comparison:


Yes I realise I want to do a numeric comparision - only problem is it doesn't work:


ERRORNUM=`grepstuff $LOGTMP |totalerrors`
echo $STATUS
echo $ERRORNUM
#if (( ERRORNUM -ge 1 ))
if [ "$ERRORNUM" -ge 1 ]
        #then let STATUS="$STATUS but with errors"
        then STATUS="$STATUS but with errors"
        else echo status screwed
fi

produces:

54
: integer expression expected
status screwed

and if I try is with round brackets as was suggested:
ERRORNUM=`grepstuff $LOGTMP |totalerrors`
echo $STATUS
echo $ERRORNUM
if (( ERRORNUM -ge 1 ))
#if [ "$ERRORNUM" -ge 1 ]
        #then let STATUS="$STATUS but with errors"
        then STATUS="$STATUS but with errors"
        else echo status screwed
fi

gives this:

54
")syntax error: operand expected (error token is "
status screwed

single round brackets:
54
./parse.sh: ERRORNUM: command not found
status screwed

I think double round brackets is what I want ((...)) from the Adv Bash HOWTO, but the syntax error throws me. It suggests that I need an operand but I clearly have one... In the last example I tried >= as well....

as for the quoting (thanks jeff) I think strings need quoting, integers don't. [] seems to be for strings, ((..)) and (...) for numbers - am I getting anywhere? hrmm...

thanks for you help so far..


dave



-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to