title: How to write a single line shell script with a while loop and if statement
body: <p>I am trying to figure out the syntax for having a while loop and an if statement that checks for more than one condition, in a single-line shell script.</p>
  
  <p>Executing something like this...</p>
  
  <pre><code>i=2; while [ $i -le 10 ]; do if [ $i -ne 3 -a $i -ne 5 ] echo $i " not equal to 3 or 5"; else echo $i; i=`expr $i + 1`; done
  </code></pre>
  
  <p>...I get the error</p>
  
  <pre><code>bash: syntax error near unexpected token `else'
  </code></pre>
  
  <p>On another hand if I remove the semicolon from between <code>...3 or 5"</code> and <code>else echo...</code>, and try something like this...</p>
  
  <pre><code>i=2; while [ $i -le 10 ]; do if [ $i -ne 3 -a $i -ne 5 ] echo $i " not equal to 3 or 5" else echo $i; i=`expr $i + 1`; done
  </code></pre>
  
  <p>...then I get the error:</p>
  
  <pre><code>syntax error near unexpected token `done'
  </code></pre>
  
  <p>This is on an Ubuntu 14.04, in case it matters.</p>
  
  <p>Am I perhaps missing some kind of a parenthesis somewhere, or is it something else?</p>