0

I have a script which I need to run with many input combinations. Currently I'm doing it with a perl script but I want to learn how to do it in a shell.

I need to run ./script.pl a b for all combinations of a=1..100 and b =1..100

for ($a = 1; $a <100; $a++) {
    for ($b = 1; $b <100; $b++) {
      system "./script.pl $a $b";
        }
}

I'm currently using bash, but zsh or tcsh work too.

0

1 Answer 1

3

You have 2 choices of syntax in bash for loops.

for VARIABLE in 1 2 3 4 5 .. N
do
    commands
done

and

for (( EXP1; EXP2; EXP3 ))
do
    commands
done

The first is similar to java loops for navigating lists etc, while the second is the old school for loop.

You can rewrite your loops as either of these.

for b in {1..100}
do
   ./script $a $b
done

or

for ((b = 1; b <100; b++))
do
   ./script $a $b
done
Sign up to request clarification or add additional context in comments.

Comments

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.