title: Why doesn't Bash `(())` work inside `[[]]`?
body: <pre><code>[[ " stop start status " =~ " $2 " &amp;&amp; (($#&lt;3)) ]] || { echo "Usage $0 file_name command"; exit 1;}
  </code></pre>
  
  <p>I frequently use the above solution to check the input range of my Bash script.</p>
  
  <p>Now I realise that the extended arithmetic expression <code>(())</code> looks like it is suppressed inside the double bracket <code>[[]]</code>.</p>
  
  <p>To illustrate the problem:</p>
  
  <pre><code>a=start; n=1; [[ " stop start status " =~ " $a " &amp;&amp; (($n&lt;3)) ]] &amp;&amp; echo ok || echo bad
  ok
  a=start; n=5; [[ " stop start status " =~ " $a " &amp;&amp; (($n&lt;3)) ]] &amp;&amp; echo ok || echo bad
  bad
  
  # But:
  a=start; n=100; [[ " stop start status " =~ " $a " &amp;&amp; (($n&lt;3)) ]] &amp;&amp; echo ok || echo bad
  ok
  </code></pre>
  
  <p>The above result is false because n not less than 3 if they are treated as numbers.
  This is the correct solution:</p>
  
  <pre><code>a=start; n=100; [[ " stop start status " =~ " $a " ]] &amp;&amp; (($n&lt;3)) &amp;&amp; echo ok || echo bad
  bad
  a=start; n=1; [[ " stop start status " =~ " $a " ]] &amp;&amp; (($n&lt;3)) &amp;&amp; echo ok || echo bad
  ok
  </code></pre>