1

Looking for some help on writing a bash script with command that call multiple variables where each variable contains list of text that needs file to run against

Here is my example.

file1.txt:

USA
EU
Asia
SouthAmerica

file2.txt:

user1
user2
user3
user4

var1=$(cat file1.txt)
var2=$(cat file2.txt)

echo $var1
USA EU Asia SouthAmerica

echo $var2
user1 user2 user3 user4

What I need is for

while read var1 var2;
do
   *command* --region $var1 --profile $var2 *do something*;

done | tee -a $var2.txt

How can I get the one command to iterate through contents of var1 and var2 to produce the results I need?

0

2 Answers 2

1

Why not just use a couple of for loops:

var1=$(cat file1.txt)
var2=$(cat file2.txt)
for i in ${var1} ; do
  for x in ${var2} ; do
    *command* --region ${i} --profile ${x} *do something*
  done
done
Sign up to request clarification or add additional context in comments.

Comments

0

It's a bit unclear what you want to achieve. If you want to execute the command for each user in each region you can use two nested while loops:

while read -r region ; do
    while read -r user ; do
        command --region "${region}" --profile "${user}"
    done < users.txt
done < regions.txt

Btw, the read builtin works different that you might assume. Check help read to see how it works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.