Loop using "for" or ???

What I need to do is run a command 32 times; each command needs to have the slave and target specified. Some one decided on a goofy naming convention and there are 4 instances of the target on 8 slaves.

Skeleton of the command is:
execute.lng Slave01 Target01-A
execute.lng Slave01 Target01-B
execute.lng Slave01 Target01-C
execute.lng Slave01 Target01-D
execute.lng Slave02 Target02-A
...
execute.lng Slave08 Target08-D

Must've made sense to someone, but to me I would have prefered a nice easy to code sequence.

Psuedo code should be something like:

foreach instance ( A B C D)
foreach slave ( 1 2 3 4 5 6 7 8 )
do
execute.lng Slave0$slave Target0$slave-$instance

end

But it is Monday and my mind is mushy from head pounding :wall:so this of course is not working in ksh or bash...

I am sure some well rested soul can tackle this!

Much thanks!

The beauty of shell scripts is that it looks almost like a pseudo code.

The solution is almost exactly as you described:

#!/usr/bin/ksh
for mInstance in $(echo "A B C D"); do
  for mServer in $(echo "1 2 3 4 5 6 7 8"); do
    echo "mInstance <$mInstance> mServer <$mServer>"
  done
done
1 Like

Well rested eyes are helpful. Key is to see that sequencing all the A,B,C,Ds is easier way to tackle.

This looks pretty good from the echo:

#!/usr/bin/ksh
for mInstance in $(echo "A B C D"); do
  for mServer in $(echo "1 2 3 4 5 6 7 8"); do
    echo "excute.lng Slave0$mServer Target0$mServer-$mInstance"
  done
done

OUTPUT:
excute.lng Slave01 Target01-A
excute.lng Slave02 Target02-A
...
excute.lng Slave07 Target07-D
excute.lng Slave08 Target08-D

Now let's see if I can change that to be a real cmd line arg and hope it runs ....

That's a useless use of backticks, or backticks-equivalent. Why not just for X in 1 2 3 4 instead of for X in $(echo "1 2 3 4")