In my script I need to create tags from specific refs on specific branches using git server API. What I'm trying to achive

I have two variables

branches="feature develop hotfix"

refs="ref-for feature ref-for-develop ref-for-hotfix" 

And I'm trying create api call with schema like this

curl -X POST <gitserverurl><feature><ref-for-feature><new-tag-name>

And so on for other branches. I've started to test loops ( for i in var ), but got nowhere. How could I archive this in bash?

1 Answer 1


I'd suggest using arrays for the branches and features, and then looping over the indices of one of the arrays:


branches=("feature" "develop" "hotfix")

refs=("ref-for feature" "ref-for-develop" "ref-for-hotfix")

for i in "${!branches[@]}"; do
  curl -X POST "<gitserverurl>${branches[i]}${refs[i]}<new-tag-name>"
  • Thank you! In a meantime I've found how to create array from single variable t="1,2,3" d="4,5,6" a=($(echo "$t" | tr ',' '\n')) b=($(echo "$d" | tr ',' '\n')) for i in {0..3} do echo "${a[i]} ${b[i]}" done Output: 1 4 2 5 3 6
    – TheD3V
    May 1, 2020 at 20:03
  • @TheD3V in bash, it would be more idiomatic to use a construct like IFS=, read -a a <<<"$t" to turn delimited strings to arrays May 1, 2020 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.