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
adding values with a loop hcclnoodles Shell Programming and Scripting 1 05-27-2008 03:42 AM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 04:38 PM
Loop through only the distinct values in a file pbekal Shell Programming and Scripting 2 02-06-2008 02:47 PM
Help In Calculation of large values in loop sandeepb Shell Programming and Scripting 6 09-13-2007 05:02 AM
For Loop and concetnating values in a variable samit_9999 UNIX for Dummies Questions & Answers 21 10-03-2006 11:06 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
getting values from variable in a loop

I have a set of variables:
f1="./someFolder"
.
.
f10="./someOtherFolder"

And I'm trying to use the following loop

for (( i = 0; i <= 10; i++ ))
do
temp=f$i
done

I'm trying the get the values from my set of variable to make directories, but I can't seem the get those value from temp. I've tried ${$temp}, and a lot of combinations of brackets and quotes, if there a way of doing this? Thank you.

Last edited by kriuz; 01-22-2008 at 11:57 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
System Shock's Avatar
Registered User
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 395
First glance, you have temp=f$one ($1), instead of temp=f$eye (f$i)
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
my bad, i meant to post it with an "i", but the question still stands, do you have any suggestions?
Reply With Quote
  #4  
Old 01-22-2008
System Shock's Avatar
Registered User
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 395
well, yeah
1.- proof read before you post, and use code tags.
2.- post the entire script. The way it is, I don't know what shell you are using (figured out it is bash, because that syntax doesn't work in korn) and I have no idea what you are doing after declaring temp.
Anyway, here's a better solution using arrays in korn:

Code:
# cat tester

#!/usr/bin/ksh
set -A FOLDERS folder1 folder2 folder3 folderwhatever
for x in $(echo ${FOLDERS[@]}); do
echo $x
done


# ./tester
folder1
folder2
folder3
folderwhatever
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:51 AM.


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

Content Relevant URLs by vBSEO 3.2.0