Changing variable name in for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing variable name in for loop
# 1  
Old 07-18-2011
Changing variable name in for loop

Hi All please help if possible. I am a Unix novice. I have a similar question to the one posted by yonderboy at about a year ago. However his solution does not work for me.

The pseudo code for my problem is as follows:
Code:
for fund in 1 2 3 4

  if (FTP is successfully) then
    FILE_SENT_fund = 'T'
  else
    FILE_SENT_fund = 'F'
  end if

done

So basically I want to have 4 variables (FILE_SENT_1.....FILE_SENT_4) all having values either T or F.
I do not want to declare 4 separate variables as there may come a time where I may be sending up to 10 files so then I will have to explicitly declare 10 variables which is undesirable.

How do I do this? Hope I am clear in my explanation.

Thank you

Last edited by Scott; 07-18-2011 at 10:43 AM.. Reason: Please use code tags
# 2  
Old 07-18-2011
do you have any plans to use arrays ??
# 3  
Old 07-18-2011
Hi Thanks,

I solved the problem by using arrays as follows:

Code:
for fund in 1 2 3 4 do
if (FTP is successfully) then
x[$fund]="T"
else
x[$fund]="F"
fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing Path Variable

Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies

2. Shell Programming and Scripting

Changing the variable using awk?

Dear all, I have kind of used both the awk/sed command and found them really useful. But at the necessity I am having right now, I need help. Actually, I would like to do the following in file script.sh PATH535="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/" ... (2 Replies)
Discussion started by: emily
2 Replies

3. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

4. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

7. Shell Programming and Scripting

Changing variables in a loop

I'm having a spot of trouble. I'm trying to test three variables for a NULL value in a bash shell script. If a null value is detected in the variable to set it to set the variable to a default value. here is what I have: testResponseA=3 testResponseB= testResponseC=4 for test in... (5 Replies)
Discussion started by: kaltekar
5 Replies

8. Shell Programming and Scripting

Changing a variable Question

I have a variable: $FILENAME = /XXXX/XXXX/XXXX/file.dat I want to set another variable that will give me this: $FILENAME2=filea.dat So basically i'm chopping up variable $FILENAME. Not sure cut will do this as i'm looking at different directories so the characther length may be... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

9. Shell Programming and Scripting

changing filenames in a directory to a number within a loop

hey guys. i'm new to shell scripting but not new to programming. i want to write a script that will take all the files in the current directory that end with a particular filetype and change all their names to a number in order. so, it would take all the jpg files and sort them in alphabetical... (30 Replies)
Discussion started by: visitorQ
30 Replies

10. Shell Programming and Scripting

IFS changing the variable value

Hi, I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name. The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies
Login or Register to Ask a Question