anthonyon
anthonyon

Reputation: 3

Nested For Loop Control Flow Sequence

for PRODUCT in ${AAA} ${BBB} ${CCC}; do
  for GITBRANCH in ${AAA_BRANCH} ${BBB_BRANCH} ${CCC_BRANCH}; do
    cd ${PRODUCT}
    git checkout ${GITBRANCH}
done;
done

My nested for loop in bash (above) does:

I want my loop to:

How can I accomplish this? Thx

Upvotes: 0

Views: 46

Answers (1)

oguz ismail
oguz ismail

Reputation: 50815

Use arrays instead and iterate over indices.

products=(aaa bbb ccc)
branches=(aaa_branch bbb_branch ccc_branch)
for i in "${!products[@]}"; do
  cd "${products[i]}"
  git checkout "${branches[i]}"
  cd -
done

Upvotes: 2

Related Questions