How to get result of sqlcmd output in variable?

Hi All,

I am looking for a solution. I am executing below command in shell script:

SQL= "select count(*) from dual"
sqlcmd --login /oracle/baccess.xml --sql  "$SQL".

I can see the result while executing above shell script. but I want to store the value of query output irrespective the return value 0 or any value. Please help me on this

---------- Post updated at 10:26 AM ---------- Previous update was at 09:46 AM ----------

Hi Everyone,

Any clue on this??


sqlcmd --login /oracle/baccess.xml --sql  "$SQL" > /tmp/sqlcmd.txt


Above command will redirect the query output to

 /tmp/sqlcmd.txt 

then you grep it or whatever operation you want to perform.

Agreed, it is better to store large things like query outputs it in a file than a variable... Depending on your system, variables may have surprisingly small maximum sizes. Keeping it in a variable also makes it harder to loop inside the shell, harder to use with external utilities, and can cause lots of quoting problems.

But for the record, you can store program output in a variable by doing:

VARIABLE=$( program statement )