title: Find the highest N values of an array in bash
body: <p>I'm trying to find the top N values in an array. So far I was able to find the highest one, but not to iterate and find the other N-1 values:</p>
  
  <pre><code>ar=(10 30 44 44 69 12 11)
  max=${ar[0]}
  for n in "${ar[@]}" ; do
      ((n &gt; max)) &amp;&amp; max=$n
  done
  echo $max
  </code></pre>
  
  <p>I think I cannot sort the array since I need to print the n higher values (e.g. 4) and the corresponding index (original position in the array).</p>
  
  <p>Example of output from my array "ar":</p>
  
  <p>value: 69, index: 4</p>
  
  <p>value: 44, index: 3</p>
  
  <p>value: 44, index: 2</p>
  
  <p>value: 30, index: 1</p>