2

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?

1
  • Why aren't you passing them as command-line arguments to script2? Commented May 23, 2011 at 12:33

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

If another set of variables has to be assigned for the same variable names again, then how it can be done? I mean, after this first set the second set of variables has to be assigned for the main script in script1, like this it has to go on. How to do that?
Not sure to understand what you mean but I think you want a for loop in script1 that launches script2 with various value varN.
Ok I updated the answer (it should works with Bourne shells. Bash and Zsh at least).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.