title: sort elements read into array
body: <p>While reading <code>find</code> results into an array I want them sorted at the same time (mp3's, so by track number, which is the first part of the file name), and thought something like this should do the trick:</p>
  
  <pre><code>mp3s=()
  while read -r -d $'\0'; do
      mp3s+=("$REPLY")
  done &lt; &lt;(sort &lt;(find "$mp3Dir" -type f -name '*.mp3' -print0))
  </code></pre>
  
  <p>but the elements in the array are never sorted correctly (by first part of file name which is mp3 track number: 01_..., 02_..., 03_..., etc.)</p>
  
  <p>Although the following gets the job done, it seems unnecessarily awkward:</p>
  
  <pre><code>mp3s=()
  while read -r -d $'\0'; do
      mp3s+=("$REPLY")
  done &lt; &lt;(find "$mp3Dir" -type f -name '*.mp3' -print0)
  
  mp3s=( $(for f in "${mp3s[@]}" ; do
      echo "$f"
  done | sort) )
  </code></pre>
  
  <p>There must be a more streamlined way to get this done, along similar lines to what I was thinking in the first example, no? I have tried reading thru <code>sort</code> on both sides of the <code>find</code> command, using its numerous options for sorting (-n, -d, etc.) but without any luck (so far).</p>
  
  <p>So, is there a more efficient way to incorporate a <code>sort</code> command while the array is initially being populated? </p>