Sending sqlplus output to a shell variable

I am trying to import a sqlplus output into a shell variable but it doesnt seem to be working.

set -x
export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF
conn username/passwd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF`
echo $DEPENDENT_CR_NO

if [[ $DEPENDENT_CR_N0 = '' ]] then
echo "there is no dependency"
else
echo "DEPENDENCY IS $DEPENDENT_CR_N0"
fi

Below is the output from the above script

+ sqlplus -s /nolog
+ 0<< \EOF
conn username/psswd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF
+ DEPENDENT_CR_NO=$'\n56240; 56242'
+ export DEPENDENT_CR_NO
+ echo '56240;' 56242
56240; 56242
+ [[ '' == '' ]]
+ echo 'there is no dependency'
there is no dependency

I am not sure why $DEPENDENT_CR_NO is coming up null in the if loop.

Thanks

Hi.

You have DEPENDENT_CR_NO (with Oh) and DEPENDENT_CR_N0 (with zero).

export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF
conn username/passwd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF`
echo $DEPENDENT_CR_NO

if [[ $DEPENDENT_CR_N0 = '' ]] then
...

Your test will also fail because without set feedback off, the variable will always contain text.

1 Like

Thanks Scott, that was a stupid mistake i made. Thanks for the quick reply.