title: How to swap array element in bash shell linux?
body: <p>I have a problem regarding about the syntax on how to swap the element value in an array.</p>
  <pre><code>array=&quot;5 3 2 1 4&quot;
  echo &quot;${array[*]}&quot;
  
  changed=1
  while [ $changed != 0 ]
  do
      changed=0
      for (( i=0 ; i&lt;=${#array[@]}-1 ; i++ )) 
      do
          if [ ${array[$i]} -gt ${array[$i+1]} ]
              then
                  tmp=${array[$i]}
                  array[$i]=${array[$i+1]}
                  array[$i+1]=$tmp
                  changed=1
          fi
      done    
  done
  
  echo &quot;Sorted array: &quot;
  echo &quot;${array[*]}&quot;
  </code></pre>
  <p>Edit:</p>
  <p>Thanks for answering my question. I have changed the code, and now and it looks something like this.</p>
  <p>But unfortunately there is still a problem.</p>
  <p>It says:</p>
  <pre><code>jdoodle.sh: line 3: $'\r': command not found
  jdoodle.sh: line 8: syntax error near unexpected token `$'\r''
  jdoodle.sh: line 8: `    for ((i=0;i&lt;=${#array[@]}-1;i++))
  </code></pre>