Reputation: 3
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:
cd
under AAA repo and check out AAA_BRANCH cd
under AAA repo and check out BBB_BRANCHcd
under AAA repo and check out CCC_BRANCHcd
under BBB repo and check out AAA_BRANCHcd
under BBB repo and check out BBB_BRANCHcd
under BBB repo and check out CCC_BRANCHcd
under CCC repo and check out AAA_BRANCHcd
under CCC repo and check out BBB_BRANCHcd
under CCC repo and check out CCC_BRANCHI want my loop to:
cd
under AAA repo and check out AAA_BRANCHcd
under BBB repo and check out BBB_BRANCHcd
under CCC repo and check out CCC_BRANCHHow can I accomplish this? Thx
Upvotes: 0
Views: 46
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