How to pass a date read from database to the shell script?

Hi
i have a database table which i will query in a sqlplus session and it will either come back with a date or null?

Now, what i want to do is based on the date returned i will either abort or continue with the script execution.

I need to know is there a way other than spooling the date into a file and checking that file later on in my shell script ,to decide whether to continue or abort?

Many thanks

echo "
set pages 0
set feedback off
select sysdate from dual;
exit;
 "  | sqlplus -s user/pwswd/somedb | tr -s '\n' ' ' | sed 's/ //g' | read answer
if [[ -z "$answer" ]] ; then
   echo "answer is null"
else
   echo "date= $answer"
fi

Hi
I just ran the code after connecting to a database but it returns null for sysdate value.

Any ideas....

---------- Post updated at 08:15 AM ---------- Previous update was at 07:59 AM ----------

Hi
I just ran the code after connecting to a database but it returns null for sysdate value.

Any ideas....

$
$ cat testscr.sh
#!/usr/bin/bash
dt=`sqlplus -s scott/tiger <<EOF
set heading off feed off pages 0
select hiredate from emp where rownum = $1;
exit
EOF`
if [ -z $dt ]; then
  echo "dt is null"
else
  echo "dt = $dt"
fi
$
$ ./testscr.sh 1
dt = 17-DEC-80
$
$ ./testscr.sh 0
dt is null
$
$

tyler_durden

thanks