title: Bash script error: [i: command not found
body: <p>This program is suppose to accept a number from the user and print that many prime numbers. For some reason the program doesn't work. I am new to bash scripting and this is my first program. To my eyes everything seems to be correct. Please tell me where I went wrong.</p>
  
  <pre><code>echo Enter num
  read n
  i=2
  j=2
  
  for(( i=2; i &lt;= n; i++ ))
  do
  
  for(( j=2; j &lt; i-1; j++ ))
  do
  
  if [i % j == 0];
  then
  break
  fi
  
  
  if [i == j];
  then
  echo "  $i"
  fi
  done
  done
  </code></pre>
  
  <p>This is the output I get </p>
  
  <pre><code>Enter num
  20
  prime.sh: line 12: [i: command not found
  prime.sh: line 18: [i: command not found
  prime.sh: line 12: [i: command not found
  prime.sh: line 18: [i: command not found
   .
   .
   .
  </code></pre>
  
  <p>After making the suggested changes</p>
  
  <pre><code>read -p "Enter a  number : " n
  i=2
  j=2
  for(( i=2; i &lt;= n; i++ ))
  do
      for(( j=2; j &lt;= i-1; j++ ))
      do
          if [ $(( i % j )) == 0 ]
          then
              break
          fi
          if [ i == j ]
          then
              echo "  $i"
          fi
      done
  done
  </code></pre>
  
  <p>I was able to run the program but it didn't produce any result</p>
  
  <p><a href="http://i.stack.imgur.com/Fd1se.png" rel="nofollow">http://i.stack.imgur.com/Fd1se.png</a></p>