The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
incorrect array values jhillier UNIX for Dummies Questions & Answers 6 01-04-2008 12:44 AM
printing all array values using dbx 7.2.1 JamesGoh High Level Programming 1 12-18-2007 12:07 PM
to assign cut values to an array Syms UNIX for Dummies Questions & Answers 6 10-29-2007 02:42 AM
Assigning values to an array yongho UNIX for Dummies Questions & Answers 4 07-13-2005 05:49 PM
array values in a command eeisken Shell Programming and Scripting 3 06-22-2005 01:49 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: Apr 2007
Posts: 5
How to use array values after the loop.

- I m retreving values from database and wish to use those values later in my shell script. I m placing these values in an array da_data but outside loop array is empty.Problem is its treating array as local inside loop hence array is empty outside loop.

Plz go through the script and suggest how to use array values after the loop.


declare -a da_data

count=0
cat $LOAD_DA_FILE | \
while read da_name
do
da_data[count]=`$ORACLE_HOME/bin/sqlplus -s username/password@instance << EOF
set heading off
set feed off

select start_date from table where derive_name='$da_name';

EXIT
EOF`
count=`expr $count + 1`
echo ${da_data[count-1]} # displaying array value

done

echo -n "Elements Of array : "
echo ${da_data[@]} # array empty


- thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 519
Try this instead:

Code:
declare -a da_data

count=0
while read da_name
do
da_data[count]=`$ORACLE_HOME/bin/sqlplus -s username/password@instance << EOF
set heading off
set feed off

select start_date from table where derive_name='$da_name';

EXIT
EOF`
count=`expr $count + 1`
echo ${da_data[count-1]} # displaying array value

done < $LOAD_DA_FILE

echo -n "Elements Of array : "
echo ${da_data[@]} # array empty
It prevents creation of a sub-process to handle the while/read loop, therefore the variables remain in the current scope.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0