Reputation: 11641
I have three commands I running in shell file (app.sh):
docker-compose -f .docker/docker-compose.my-app1.yml push my-app1
docker-compose -f .docker/docker-compose.my-app2.yml push my-app2
docker-compose -f .docker/docker-compose.my-app3.yml push my-app3
how to create array and pass the values to command with foreach?
say if it's was nodejs I'll do:
['my-app1', 'my-app2', 'my-app3'].forEach(i => {
… `-f .docker/docker-compose.${i}.yml push ${i}` ...;
})
Upvotes: 2
Views: 838
Reputation: 17159
In BASH you can have arrays and for loops as follows
arr=( 'my-app1' 'my-app2' 'my-app3' )
for i in "${arr[@]}" ; do
docker-compose -f ".docker/docker-compose.${i}.yml" push "${i}"
done
Note, that you do not need to use commas to separate array elements as whitespace is a token separator in BASH.
Upvotes: 3