shell script cant recognize if else compare

hi

I face the problem the if else statement dint return correct result for me
my script as below:

#!/bin/ksh
sqlplus -s /nolog <<EOF
connect databaseuser/password
column num new_value num format 9999
set head off
select count(*) num from table1;
exit num
EOF

if [ $? -gt 10 ]; then
echo "$?"
else
echo "stop"
fi

-----
How I know $? is integer? Is it because both is not integer
so cant go the compare??

Any one please help ,

Thanks and regards,
Jase

what exactly your if is returning?

What are you actually trying to compare with 10? If it is the output of the query i.e. (count(*) ) that you are trying to compare with 10 then you can use the following code.

#!/bin/ksh
RESULT=`sqlplus -s /nolog <<EOF
connect databaseuser/password
set head off
select count(*) from table1;
EOF`

if [ $RESULT -gt 10 ]; then
echo $RESULT
else
echo "stop"
fi

Thanks for your reply
Yes, I need to compare the result from the query, if the count(*) > 10 then some action I need to take...but it seem like the result is not integer..so it cant be compare with number.. got any way to convert it to integer..

sowjanya.addala
I had try this before but the RESULT cant go to proceed the sql statement inside. The value of the RESULT is just capture the SQL statement not the output query.
any way appreciate your help.

regards,
Jase

look at this

#!/bin/ksh
RESULT=`sqlplus -s /nolog <<EOF
connect databaseuser/password
set head off
spool log;
select count(*) from table1;
EOF`
RESULT=`head log.lst`
if [ $RESULT -gt 10 ]; then
echo $RESULT
else
echo "stop"
fi

Things are being unnecessarily complicated here. Try this:

#!/usr/bin/ksh

count=$(sqlplus -s /nolog << !|egrep -v "^$|Connected"
conn user/passwd;
set head off feed off;
select count(*) from some_table;
quit;
!)
echo $count

Please remember that any '$' signs in the query are to be escaped with '\'.

Hi all,

Thanks for your help. my problem solve.
I jst change the #!/bin/ksh to #!/bin/sh, then it can work properly.
But I dont know why....

regards,
Jase