Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Sending sqlplus output to a shell variable

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-17-2012
beginer314 beginer314 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 December 2012, 2:37 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
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.

Code:
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


Code:
+ 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

Last edited by Scott; 12-17-2012 at 02:10 PM.. Reason: Please use code tags
Sponsored Links
    #2  
Old Unix and Linux 12-17-2012
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 1 September 2015, 7:26 AM EDT
Location: Zürich
Posts: 8,575
Thanks: 337
Thanked 1,080 Times in 938 Posts
Hi.

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


Code:
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.
The Following User Says Thank You to Scott For This Useful Post:
beginer314 (12-17-2012)
Sponsored Links
    #3  
Old Unix and Linux 12-17-2012
beginer314 beginer314 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 December 2012, 2:37 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Scott, that was a stupid mistake i made. Thanks for the quick reply.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sending Sed/Echo output to Variable nitrobass24 Shell Programming and Scripting 4 08-28-2012 04:25 PM
Log sqlplus output from Shell WhoDatWhoDer Shell Programming and Scripting 2 06-15-2011 11:26 AM
store sqlplus output in variable murtymvvs Shell Programming and Scripting 1 12-04-2010 12:46 PM
error in passing a variable to sqlplus from a shell script kripssmart Shell Programming and Scripting 3 07-08-2008 07:01 PM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 02:31 PM



All times are GMT -4. The time now is 10:23 PM.