jasperes/bash-yaml

not getting array

pratikbin opened this issue · 0 comments

Description

There should be two host in spec__host but instead, there is 1, I'm puttng my bash file with the output which is wrong in the case of db

Yaml file to test

backupname: mybakcup
spec:
 -  host: localhost
    port: 25060
    awsid: AAA
    awskey: BBB
    dbs:
    - dbname: testdb1
      username: db1_username
      passowrd: db1_password
    - dbname: testdb2
      username: db2_username
      passowrd: db2_password
 -  host: localhost2
    port: 2222
    awsid: ZZZZ
    awskey: XXXX
    dbs:
    - dbname: testdb1
      username: db1_username
      passowrd: db1_password
    - dbname: testdb2
      username: db2_username
      passowrd: db2_password

Bash file

 echo "No of Hosts found ${#spec__host[@]}"
  for i in ${!spec__host[@]}; do
      echo ${spec__host[$i]} ${spec__port[$i]} ${spec__awsid[$i]}
      for i in ${!spec___dbname[@]}; do
          echo "No of DB found ${#spec___dbname[@]}"
          echo ${spec___dbname[$i]} ${spec___username[$i]} ${spec___passowrd[$i]}
      done
  done

output

No of Hosts found 1
localhost2 2222 ZZZZ
No of DB found 4
testdb1 db1_username db1_password
testdb2 db2_username db2_password
testdb1 db1_username db1_password
testdb2 db2_username db2_password 

Operation Sistem

[x] Linux
[] OSX
[] BSD

Bash version

GNU bash, version 5.1.0(1)-release (x86_64-pc-linux-gnu)