The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Storing value in a variable gehlnar Shell Programming and Scripting 2 02-04-2009 12:22 PM
Storing Command Line Values yoursdavinder Shell Programming and Scripting 3 01-30-2009 07:33 AM
storing a command in a variable nookie Shell Programming and Scripting 2 10-11-2008 11:55 AM
Storing a variable? hoover90 Shell Programming and Scripting 4 01-26-2008 09:39 PM
Storing values in variable matrixmadhan Shell Programming and Scripting 1 04-01-2005 02:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-02-2009
sandeep_1105 sandeep_1105 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 29
Storing Multiple Values in a Variable

Hi,

My code is as below:

integer i=7
while ((i <= 5 ));
do
# test_out is a variable which contains data separated by "^".

a= `echo $test_out | cut -d"^" -f$i`

echo "$a"

(( i = i + 1));
done



From the above code, i kept $i after f so that i can capture all the data which is separated by "^". Here since "i" is incrementing 5 times, i want to store all the 5 values in variables such as a1,a2,a3,a4,a5 .

How can i do this. If i keep "i" after a it is not working. Ideally instead of keeping 5 commands for a, i want to do it in single shot by keeping ai. But it is not working.

If i do an echo "$ai", it must display all the 5 values since its looping 5 times.

Correct me if i mentioned some thing wrong. I am new to UNIX so it would be great if some body can help me out.

Thanks
Sandeep
  #2 (permalink)  
Old 03-03-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,945
Assuming you are using the Korn shell, the following example should show you how to do what you want

Code:
integer i=1

while ((i <= 5 ))
do
   eval 'a'$i'=$i'
   (( i++ ))
done

echo "$a1 $a2 $a3 $a4 $a5"

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 07:02 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