title: Insertion Sort in bash
body: <p>Can you please help me to understand why this piece of code is not working. I am meant to write insertion sort and apply it to the file to sort its elements. However, it even fails to print the k-th elements in the while construct. I am using Windows and working in Git Bash.</p>
  
  <pre><code>j=0
  for line in $(cat $1)
  do
          elements[$j]="$line"
          j=$((j+1))
  done
  
  
  for i in $(seq "${#elements[@]}");
  do
          key=${elements[i]}
          echo index: $i Key: $key
          k=$((i-1))
          while [ $k -gt 0 ] &amp;&amp; [ ${elements[k]} &gt; $key ]; do
                  echo ${elements[k]} $key
                  elements[$((k+1))]=${elements[k]}
                  k=$((k-1))
          done
          elements[$((k+1))]=$key
  done
  </code></pre>
  
  <p>The file I am reading as array elements is a .txt file with the following information:</p>
  
  <pre><code>3
  1
  2
  3
  2
  
  
  </code></pre>