While loop variable

while read -r tabname rem
do
  select count(*) from $tabname" > /dev/null
  RC=$?
  if [[ $RC != 0 ]]
  then
         echo "error on $tabname" >> error.out
         
  fi
done  

well in above code i need the echo "error on $tabname" to come in separate o/p file which show the table name whc doesn't pass RC =0. but not getting any o/p in erro.out.Any thing that need to check.??

Doesn't your shell show any error on this line when executing the script?

select count(*) from $tabname" > /dev/null

hi zaxxon,

actually the code i shown you is not complete ..it has db connection.That part is runnign fine Rc is validating but the Problem is m not getting error.out in separate file.

echo "error on $tabname" >> error.out

Ok :wink:
The problem will most probably be, that the DB client you are using, will just show a RC of 0 all the time, no matter if the SQL statement issued was successful or not.
You got the same issue, if you do something with a ftp client or any other client, that works fine in terms of itself, no matter what errors you get "inside" the client. There is usually issued a 0 back to the shell as the client says "Hey man, I am fine, not my fault the commands you issued didn't work because of <insertsomethingthatwentwrong>".

Can simply check this if you add a echo $RC after defining $RC while issuing an intentionally failing SQL statement in the line above.
I am not sure if there is any kind of option for your DB client to pass any other RC through to the shell. Could check it's documentation maybe; or grep for a pattern that shows the success/fail of the operation.

Update:
For DB2 I found that the client returns appropriate RCs:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0010411.htm
Just as an example that some clients do that.