echo "select STATUS from v$instance;
select VERSION from v$instance;
select VERSION from v$instance;
" > $SQL_FILE
sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT
This sentence does not make any sense. Also your second and third queries are the same.
Please give a good clear example making it clear what is a file and what is a variable. Please make is clear whether any or all of them are different for each query.
You could combine the queries into one query:
select version,status from v$instance;
Also personally I would use an Oracle "spool" command to write the results to a file (i.e. not a Shell redirect).
This has been tested on Solaris using dtksh and Oracle 10g.
Construct the query so it returns rows as name=value, so they can be used in the shell script.
Read the query output a line at a time.
for each row returned, if it is not null, use eval to make it a shell variable.
#!/usr/dt/bin/dtksh
# Oracle environment is assumed to be set already.
unset version # Remove variable names from the environment if they exist.
unset status
( sqlplus -s / <<EOF
set heading off;
select 'version='||'1.2' from dual;
select 'status='||'UP' from dual;
exit;
EOF
)|
while read line
do
if [[ -n $line ]]
then eval $line
fi
done
print "Version: $version"
print "Status: $status"