The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
split varibles and store fields into shell varible array gratus Shell Programming and Scripting 3 10-11-2007 02:50 PM
Grep results to store in a shell variable jojan Shell Programming and Scripting 3 07-26-2007 12:44 PM
passing result of query to a varibale in ksh script ammu Shell Programming and Scripting 2 07-27-2006 01:05 AM
When can a script deny to store any value in a variable mitte_dino Shell Programming and Scripting 1 10-04-2005 06:57 AM
how do I store the values in array using shell krishna UNIX for Advanced & Expert Users 2 08-17-2001 09:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2007
div_Neev div_Neev is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 12
Question How to store query multiple result in shell script variable(Array)


Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable.

like

#!/bin/ksh

v_shell_var[0]=Hi

here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array).

Regards,
Div
  #2 (permalink)  
Old 10-31-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
One way
Code:
#!/bin/ksh

let i=0
set -A arr 
USER=username
PWD=password

echo "
SELECT fld1 
 from TABLEA;
exit 
" | sqlplus -s $USER/$PWD | \
while read line
do
     arr($i)="$line"
     let i=$i+1
done
  #3 (permalink)  
Old 11-01-2007
div_Neev div_Neev is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 12
Smile Thanks jim

You have given reply is very usefull. again thanks to you.

Just in Below code I have change array box with [] and add new code for print the array member.

#!/usr/bin/ksh

let i=0
#set -A arr

echo "select param_value
from control_param
where pgm_name = 'EXS_PROCESS';
exit
" | sqlplus -s ${ora_user}/${ora_passwd}@${ORACLE_SID} | \
while read line
do
if [[ $i -gt 2 ]]
then
arr[$i-3]="$line"
fi
let i=$i+1
done
echo "Array Variable is Filled Up"
i=0
echo " Total no. of member ${#arr[@]} "
echo "Print the Array member"
while [ $i -lt ${#arr[@]}-1 ]
do
print ${arr[$i]}
(( i=i+1 ))
done
echo "After Array Print"
  #4 (permalink)  
Old 11-01-2007
div_Neev div_Neev is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 12
Question Would like to ask more thing. How Can I cond. check, pattern matchig and cp file

Here, Situation is I have arr[] array. suppse
arr[0]=OWCD
arr[1]=SPCS contains
I want to if this pattern(arr[0] or arr[1]) match in ../Innovation dir's file then this file copy --> zip format --> into ../zipdir dir.
If pattern is not found then copy into ../archive dir area

I have tried below code...but not running. I feel , step 6/7 might be modified but how...please help me.

1. i=0
2. for j in `ls ../Innovation`
3. do
4. while [ $i -lt ${#arr[@]}-1 ]
5. do
6. # awk /${arr[$i]}/ { `cp $j ../archive`; } $j
7. source_dir=$($j | head -1 | grep -i ${arr[$i]} | cp ../Innovation/$j ../archive)
8. done
9.done
  #5 (permalink)  
Old 11-06-2007
unishiva unishiva is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 11
Processing Command line Parameteres in to array

I need to get files names passed to a script. Here number of files passed may vary
like MyScript.ksh file1 file2 file3..... so on

I am writting script somthing like this

set -A Files

while (i<=$#)
do
File[i]=$i
let i=i+1
done

Is this correct way doing this. Is there any other way.
Please let me know

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0