Venky
Venky

Reputation: 31

How to use variables in another shell script in a loop in my main script?

I already mentioned in my last question that I have a main method in script1 which has to run for each set of variables in script2.

I want to run the main script again and again for each set of variables (var1 to var8 since the main method utilises 8 variables to run) in script2.

How do I achieve this?

Upvotes: 2

Views: 625

Answers (1)

log0
log0

Reputation: 10917

script1:

var1=(a b c)
...
var8=(98 545 4)
for (( i = 0 ; i < 3 ; i++ ))
do
  script2 ${var1[i]} ... ${var8[i]}
done

script2:

if [ $# -eq 9 ]; then  # $# is the total number of arguments.
    var1=$1
    ...
    var8=$8
fi

Upvotes: 1

Related Questions