title: How to use variables in bash conditional expression?
body: <p>I'd like to have some explanation on how to best use variables in bash conditional expressions <code>[[...]]</code>.</p>
  
  <p>I usually write <code>if</code> statement in this way:</p>
  
  <pre><code>var=1;
  # some code...
  if [[ $var -eq 1 ]]; then echo "ok"; else echo "fail"; fi
  </code></pre>
  
  <p>and this return <code>ok</code> as I expected. </p>
  
  <p>Now I saw in some script the same similar statement like:</p>
  
  <pre><code>var=1;
  # some code...
  if [[ var -eq 1 ]]; then echo "ok"; else echo "fail"; fi
  </code></pre>
  
  <p>The only difference is the missing parameter expansion character <code>$</code> in the conditional expression <code>[[...]]</code>.</p>
  
  <p>I actually expected this statement to give an error, but this syntax is accepted and returns the <code>ok</code> string.</p>
  
  <p>I tested this statement using <code>bash</code> (GNU bash, version 4.3.46), <code>zsh</code> (5.1.1), <code>ksh</code> (93u+ 2012-08-01) and busybox <code>ash</code> (BusyBox v1.23.2).</p>
  
  <p>I only get an error with busybox shell:</p>
  
  <pre><code>ash: var: bad number
  </code></pre>
  
  <p>I saw in the <code>bash</code> man page, in the <code>ARITHMETIC EVALUATION</code> paragraph, that:</p>
  
  <blockquote>
    <p>Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax</p>
  </blockquote>
  
  <p>But I didn't find anything special related to parameter expansion in the <code>CONDITIONAL EXPRESSIONS</code> paragraph.</p>
  
  <p>So, should conditional expression contain <code>$</code> when referring to variable or not? and why?</p>