problem in comparing numeric with string

Hi all,

I am having a problem in comparing numeric value with string.
I have a variable in my script which gets the value dynamically. It can be a numeric value or a string. [ FILE_COUNT=5 (or) FILE_COUNT="VARIABLE" ]

I have to do separate task based on its value numeric or sting variable VARIABLE.

I grep FILE_COUNT and obtained the value. But its giving error when i did either
if [ $FILE_COUNT = "VARIABLE" ]
or
if [ $FILE_COUNT -eq "VARIABLE" ]
as it is not two numeric or two string comparisons.

I tried using test also likewise
if [ test $FILE_COUNT = "VARIABLE" ] but invain :frowning:

I am thinking of using "typeset -i <variable>" concept but it assigns 0 if it is a string and the dynamic value that i receive can also be 0.

So, can you please give me some light in to this issue to let me move forward in this.

Thanks in advance,

Naren

does this help:

if [ $FILE_COUNT == "VARIABLE" ] ; then
  echo "is VARIABLE"
else
  echo "is a number"
fi

It is still showing the error message using the == operator
expr: 0402-050 Syntax error.

The one that yogesh is mentioning above should work for both numeric and string comparison. A different look of the same.

$ VAR=25
$ [ $VAR == "25" ] && echo "Y" || echo "N"
Y

$ VAR=25A
$ [ $VAR == "25A" ] && echo "Y" || echo "N"
Y

You people are right. But what i am trying is not numeric to numeric or string to string comparison. But it is like
$ VAR=25
And i want to check if $VAR is "25A" or not. Likewise
$ if [ $VAR == "25A" ] { .........} else { ..........}

And this is giving error.

maybe something like:

if [[ $VAR == 25* ]]

#!/bin/sh

export VAR1=$1

export VAR2=`echo $VAR1 | tr '[:lower:]' '[:upper:]' | sed 's/[A-Z]//g'`

echo "VAR1=$VAR1, VAR2=$VAR2"

if [ x"$VAR1" != x"$VAR2" ]
then
        echo "VARIABLE !!!"
else
        echo "NUMERIC !!!"
fi
./titi 2634
VAR1=2634, VAR2=2634
NUMERIC !!!

./titi 2634Bhj
VAR1=2634Bhj, VAR2=2634
VARIABLE !!!

./titi 26efg34Bhj
VAR1=26efg34Bhj, VAR2=2634
VARIABLE !!!

I have a variable in my script which gets the value dynamically. It can be a numeric value or a string

If the variable is FILE_COUNT :

VAR_TEMP=`echo $FILE_COUNT | tr '[:lower:]' '[:upper:]' | sed 's/[A-Z]//g'`

if [ x"$FILE_COUNT" != x"$VAR_TEMP" ] ; then
        echo "VARIABLE !!!"
else
        echo "NUMERIC !!!"
fi