title: Concatenating string variable inside a for loop in the bash shell
body: <p>I have a file config.ini with the following contents:</p>
  
  <pre><code>@ndbd
  </code></pre>
  
  <p>I want to replace <code>@ndbd</code> with some other text to finalize the file. Below is my bash script code:</p>
  
  <pre><code>ip_ndbd=(108.166.104.204 108.166.105.47 108.166.56.241)
  
  ip_temp=""
  for ip in $ip_ndbd
  do
      ip_temp+="\n\[ndbd\]\nHostname=$ip\n"   
  done
  perl -0777 -i -pe "s/\@ndbd/$ip_temp/" /var/lib/mysql-cluster/config.ini
  </code></pre>
  
  <p>Basically, I just want to get all the ip addresses in a specific format, and then replace <code>@ndbd</code> with the generated substring.</p>
  
  <p>However, my for loop doesn't seem to be concatenating all the data from <code>$ip_ndbd</code>, just the first item in the list. </p>
  
  <p>So instead of getting:</p>
  
  <pre><code>[ndbd]
  HostName=108.166.104.204 
  
  [ndbd]
  HostName=108.166.105.47 
  
  [ndbd]
  HostName=108.166.56.241
  </code></pre>
  
  <p>I'm getting:</p>
  
  <pre><code>[ndbd]
  HostName=108.166.104.204 
  </code></pre>
  
  <p>I'm pretty sure there's a better way to write this, but I don't know how.</p>
  
  <p>I'd appreciate some assistance.</p>
  
  <p>Thanks in advance.</p>