Here are the details of my issue:
env-attributes.yml
contents:
environments:
- env_name: development
account_id: "11111111111"
account_name: myapp-dev
user_id: svc-dev
- env_name: staging
account_id: "22222222222"
account_name: myapp-stg
user_id: svc-stg
- env_name: production
account_id: "33333333333"
account_name: myapp-prod
user_id: svc-prod
parse-yml.sh
contents:
env_count=$(yq '.environments | length' env_attributes.yml)
for i in $(seq 1 $env_count)
do
env_name=$(yq '.environments[$i].env_name' env_attributes.yml)
account_id=$(yq '.environments[$i].account_id' env_attributes.yml)
account_name=$(yq '.environments[$i].account_name' env_attributes.yml)
user_id=$(yq '.environments[$i].user_id' env_attributes.yml)
echo "${env_name}"
echo "${account_id}"
echo "${user_id}"
echo " "
done
Running parse-yml.sh
, I get the following output:
development
staging
production
11111111111
22222222222
33333333333
svc-dev
svc-stg
svc-prod
development
staging
production
11111111111
22222222222
33333333333
svc-dev
svc-stg
svc-prod
development
staging
production
11111111111
22222222222
33333333333
svc-dev
svc-stg
svc-prod
The expected output is:
development
11111111111
myapp-dev
svc-dev
staging
22222222222
myapp-stg
svc-stg
production
33333333333
myapp-prod
svc-prod
How can I get the expected output?