title: capture db2 output in shell script
body: <p>I have to convert a shell script from Oracle to db2. I found on this forum a sample of Oracle script I used ; it looks like this</p>
  
  <pre><code>#!/bin/bash
  OUT=`$ORACLE_HOME/bin/sqlplus -s user/pass@instance   &lt;&lt; EOF
  select sysdate from dual;
  exit success
  EOF`
  echo $OUT
  </code></pre>
  
  <p>This will output "03-OCT-11" (Oracle sysdate). My db2 script looks like this </p>
  
  <pre><code>#!/bin/bash
  db2bin="/users/db2inst1/sqllib/bin"
  #connect
  $db2bin/db2 connect to myschema;
  #query
  $db2bin/db2 "SELECT CURRENT_DATE FROM SYSIBM.SYSDUMMY1 WITH UR";
  #debug
  echo $?
  #check
  if [ $? = "0" ] then         echo "found-do something"
  else        echo "not found-good bye"
  fi
  #terminate
  $db2bin/db2 quit;
  </code></pre>
  
  <p>It works but does not retrieve the date ; only "0" or "1" (true/false). How can I retrieve the date from my Db2 query result??</p>