Visit Our UNIX and Linux User Community

Using multiple values for single variable in a loop

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using multiple values for single variable in a loop
# 1  
Old 12-07-2011
Using multiple values for single variable in a loop

Hello Guys,

I have a small loop problem as below.

I have 3 different values to be used while running the same script -

Now I want to use these three variable values to be used for running the same command, like -
while (i=0,i<=3,i++)
  bin/java -s (run something with $var);

Now I want $var taking the value of var1, var2 and var3 each time it runs,

so can someone please tell me how do we achieve the above?

I tried doing -
for $1 $2 $3

    case 1
    case 2
    case 3

while read a b c
    <code assumed to have loop iteration>
done <<< $(command)

But it isnt working as expected... Would really appreciate your help on this.


Last edited by Franklin52; 12-08-2011 at 03:21 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 12-07-2011
for X in "value1" "value2" "value3'
         echo "X is now $X"

Previous Thread | Next Thread
Test Your Knowledge in Computers #19
Difficulty: Easy
Vint Cerf is generally referred to as the 'Father of the Internet'.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable values within for loop

Hi All I am trying to fetch the size of three files into three separate variables within a for loop and am doing something like this: for i in ATT1 ATT2 ATT3 do size_$i=`ls -ltr $i | awk '{print $5}'` echo ${size_$i} done but am getting the below error: ksh: size_ATT1=522: not... (3 Replies)
Discussion started by: swasid
3 Replies

2. Shell Programming and Scripting

Moving multiple filetype in a single loop

Hi, I am using the below code to move *.sh files to another directory. use File::Copy qw(move); while(<C:/Users/pandeesh/Desktop/*.sh>) { move $_,"C:/Users/pandeesh/Desktop/Projects"; } My requirement is i want to move *.sh,*.txt,*.xlsx,*.doc,*.pdf and *.epub files to the specified... (2 Replies)
Discussion started by: pandeesh
2 Replies

3. Shell Programming and Scripting

Reading multiple values in while loop

I'm having trouble with a simple piece of code. IFS=, echo "1,2,3,4,5,6,7,8" | while read x y do echo "x=$x" echo "y=$y" done I'm hoping for x=1 y=2 x=3 y=4 . . . but I'm getting x=1 (3 Replies)
Discussion started by: sabbata
3 Replies

4. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

5. 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

6. Shell Programming and Scripting

Switching from a single variable to multiple

I apologize in advance if someone has answered this question before, but I am not sure even what to search for here. I have this script for backing up DB2 databases and it works fantastically if there is only on database in the config. My problem is that I have a business intelligence server that... (3 Replies)
Discussion started by: Clay Lovett
3 Replies

7. Shell Programming and Scripting

Combine 2 values into single variable

Hi gurus, I need to manipulate the output of a database query. The output contains 2 fields (asset and serial number) and I'd like to combine them into a single value, seperated by whitespace. the orginal data is in seprate fileds and of the following format: asset serial asset serial etc ... (6 Replies)
Discussion started by: melias
6 Replies

8. Shell Programming and Scripting

redirecting values from one variable to another in a loop.

The situation is like this: I am reading records from a file, depending upon some condition extracting fields from the file into different variables in a loop one by one. I need to print all the variable in line, so I am trying to redirect hose variables one by one to a variable called final_value... (1 Reply)
Discussion started by: mady135
1 Replies

9. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: kriuz
3 Replies

10. UNIX for Dummies Questions & Answers

For Loop and concetnating values in a variable

Hi, I have file abc.txt which has keys and emails addresses abc.txt I have a shell script where i pass key as the parameter and i want all the email addresses within that key concatenated by a comma... (21 Replies)
Discussion started by: samit_9999
21 Replies

Featured Tech Videos