title: How to preserve indention and spaces in array of cat <<-EOF
body: <p>Can you see why the following is removing indention and spaces, when added to array:</p>
  <pre><code>show_config(){
  
      HOSTS_LIST=(&quot;1.2.3.4&quot; &quot;5.6.7.8&quot;)
  
      TARGET_ENDPOINTS=()
  
      for index in &quot;${!HOSTS_LIST[@]}&quot;; do
  
        HOST=&quot;${HOSTS_LIST[index]}&quot;
  
  ENDPOINT=$(cat &lt;&lt;-EOF
                - endpoint:
                    health_check_config:
                      port_value: 6443
                    address:
                      socket_address:
                        address: $HOST
                        port_value: 60051
  EOF
  )
    # echo &quot;$ENDPOINT&quot;
    TARGET_ENDPOINTS+=( $ENDPOINT )
  done
  
    echo &quot;${TARGET_ENDPOINTS[*]}&quot;
  }
  </code></pre>
  <p>I get:</p>
  <pre><code>- endpoint: health_check_config: port_value: 6443 address: socket_address: address: 1.2.3.4 port_value: 60051 - endpoint: health_check_config: port_value: 6443 address: socket_address: address: 5.6.7.8 port_value: 60051
  </code></pre>
  <p>Expected:</p>
  <pre><code>         - endpoint:
                health_check_config:
                  port_value: 6443
                address:
                  socket_address:
                    address: 1.2.3.4
                    port_value: 60051
            - endpoint:
                health_check_config:
                  port_value: 6443
                address:
                  socket_address:
                    address: 5.6.7.8
                    port_value: 60051
  </code></pre>
  <p>I can see, if I echo each item in the array in the loop it prints out each element as:</p>
  <pre><code>          - endpoint:
                health_check_config:
                  port_value: 6443
                address:
                  socket_address:
                    address: 1.2.3.4
                    port_value: 60051
  </code></pre>
  <p>But when I add items to the array <code>TARGET_ENDPOINTS+=( $ENDPOINT )</code> the indentions and spaces is removed when echoing out the array echo <code>&quot;${TARGET_ENDPOINTS[@]}&quot;</code>?</p>