title: Syntax error near unepected token do
body: <p>This is my code for a bubble sort on n numbers:</p>
  
  <pre><code>#!/bin/bash
  
  echo -n  "Input n, the number of numbers"
  read N
  declare -a array[N]
  echo -e "Input the elements, press enter after each element"
  for i in seq 1 $N  
  do 
      read array[$i]
  done
  
  swap1()
  { # for swapping two numbers, we are employing bubble sort
      local temp = ${array[$1]} 
      array[$1] = ${array[$2]}
      array[$2]=$temp
      return
  }
  
  numb_elements=${#array[@]}
  let "comparisons = $numb_elements - 1"
  
  count=1
  
  while [ "$comparisons" -gt 0]
  do
     index =0
  
     while[ "$index" -lt "$comparisons" ];do
        if [ ${array[$index]} \&gt; ${array[ 'expr $index + 1']} ]
        then 
           swap1 $index 'expr $index + 1'
        fi
        let "index += 1" # Or, index+=1 on Bash, ver. 2.1 or newer
     done
  
     let "comparisons -=1"
     echo 
     echo "$count: ${array[@]}
     echo
  
     let "count +=1"
  done
  exit 0
  </code></pre>
  
  <p>I have two problems with this code:</p>
  
  <ol>
  <li>the input array just takes 3 numbers</li>
  <li>and then i get an error on line 42 saying syntax error for the command while do</li>
  </ol>
  
  <p>I have tried <code>while [] ; do</code>, but it doesn't work.</p>
  
  <p>Its just been a day that i have been trying bash syntax.</p>