how to create variables in loop and assign filename after set command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create variables in loop and assign filename after set command?
# 1  
Old 03-17-2010
how to create variables in loop and assign filename after set command?

Hi,

does anybody knows how to manage, that the filenames are assigned to a variable in a loop afer getting them with set command in a ksh, like:

Code:
set B*.txt
i=1
c=$#
x=$((c+1))
echo "$x"
while [[ $x -gt i ]] ; do
_ftpfile$i="$"$i
echo "$_ftpfile$i"
i=$((i+1))
done

The first echo returns, that x = 4, and as long x is not gt. than i(=1), it should create a variable _ftpfile$i (_ftpfile1, _ftpfile2, _ftpfile3) with the value of the set command, means the filename in $i (which should be $1, $2 and $3).

here's the output:

4
awkb.ksh[13]: _ftpfile1=$1: not found
1
awkb.ksh[13]: _ftpfile2=$2: not found
2
awkb.ksh[13]: _ftpfile3=$3: not found
3


Thanks,
M
# 2  
Old 03-17-2010
I think you should replace :
Code:
_ftpfile$i="$"$i

by
Code:
eval "_ftpfile$i=\$$i"

# 3  
Old 03-17-2010
perfekt, thnx!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I assign the output of a command to a variable within a loop in bash?

In the else of the main if condition . else set lnk = $(readlink -f <path> | cut -d '/' -f7) echo "$lnk" if ] When I run the above on command line , the execution seems to be fine and I get the desired output. But when I try to assign it to a variable within a loop... (12 Replies)
Discussion started by: sankasu
12 Replies

2. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Need one line command to create and set password for new user...

Using useradd abc --password password (5 Replies)
Discussion started by: Jagruti Rml
5 Replies

4. Shell Programming and Scripting

Using the set command to redefine shell variables

so i'm havin a bit of a issue getting set to recognize a value with spaces as a variable. this is what i'm doing: VAR="1 2 4 11 'dogs mouse cars' 50 19 'noise toys' " set -- ${VAR} When i issue a command such as the one below: echo $5 or echo "${5}" i get dog when i... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

Unable to read assign values to two variables in while loop

I am trying to read a input file which has two columns separated by space Input file server1 server2 server3 server4 server5 server6 When i execute the below while code it reads line by line and a and b variables are able to successfully fetch the values while read a b do echo "$a" echo... (5 Replies)
Discussion started by: chidori
5 Replies

6. Shell Programming and Scripting

Set variables from file, then loop

Hello, I am very, very new to shell scripting, but what I'm attempting to do is read in a list of user ID's to create on a database system from a CSV flat file, and for each entry run the "create user" script. I've gotten pretty far but I'm having trouble with the looping mechanism.... Any... (8 Replies)
Discussion started by: jkarren
8 Replies

7. Shell Programming and Scripting

Setting Variables WITHIN For Loop in DOS Command Shell

I'm wondering if any of you could lend an assist with a small problem. First, I'm under the impression I need to use Delayed Environment Variable Expansion (DEVE), based on other things I've read across the web. Summary: trying to use command shell (cmd.exe) in XP sp3 (if that's relevant) to... (4 Replies)
Discussion started by: ProGrammar
4 Replies

8. UNIX for Dummies Questions & Answers

SET Command removed the variables

Hi, Im using csh and sometimes bash. I accidentally typed SET and looks like it has resetted some enviroment variables as im not able to run autosys jobs etc .. So i wanted to know how i can put it back to normal by replacing any profile files from another user or by editing the file which... (2 Replies)
Discussion started by: spectator
2 Replies

9. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

10. Shell Programming and Scripting

declare, assign variables using array, counter, loop

using bash Tru64... converting DCL to shell... any tips to make this work would be greatly appreciated. Below is my failed attempt to assign command line input to variables by first declaring an array. I use a counter to create unique variables in a loop through the array. I need to call... (3 Replies)
Discussion started by: egkumpe
3 Replies
Login or Register to Ask a Question