title: Bash: Append 'find'-results to indexed array using loop
body: <p>I have the following code which isn't working:</p>
  <pre><code>declare -a pids
  find /foo/bar/ -iname &quot;*.pid&quot; -print0 | while read -d $'\0' file
  do
       pids+=(&quot;$file&quot;)
  done
  
  for i in &quot;${pids[@]}&quot;
  do
       echo $i
  done
  </code></pre>
  <p>It should create an indexed array, search the given folder for all PIDs and append them to the array using a while loop however it seems that nothing is happening.</p>
  <p>For me it looks like the results of <code>find</code> don't get appended to the array because the for loop at the bottom doesn't echo anything. I'm not sure if the <code>+=</code> operant is correct for this but looking at similar question it seems to be. When trying to manually append a value to the array <code>pids</code>, instead of creating a new value on the next index it just adds the string to the first value (index 0).</p>
  <p>For example this:</p>
  <pre><code>declare -a pids
  pids+=&quot;foo1&quot;
  pids+=&quot;foo2&quot;
  </code></pre>
  <p>results in this:</p>
  <pre><code>pids[0]=&quot;foo1foo2&quot;
  </code></pre>
  <p>instead of:</p>
  <pre><code>pids[0]=&quot;foo1&quot;
  pids[1]=&quot;foo2&quot;
  </code></pre>
  <p>Is <code>+=</code> not the right operant for this or is something else wrong?</p>