Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's describe them here.</p> <p>First of all, there are basically 3 different test methods</p> <ul> <li><code>[ EXPRESSION ]</code>, which is exactly the same as <code>test EXPRESSION</code></li> <li><code>[[ EXPRESSION ]]</code></li> <li><code>(( EXPRESSION ))</code>, which is exactly the same as <code>let "EXPRESSION"</code></li> </ul> <p>Let's go into the details:</p> <h1><code>test</code></h1> <p>This is the grandfather of test commands. Even if your shell does not support it, there's still a <code>/usr/bin/test</code> command on virtually every unix system. So calling <code>test</code> will either run the built-in or the binary as a fallback. Enter <code>$ type test</code> to see which version is used. Likewise for <code>[</code>.</p> <p>In most basic cases, this should be sufficient to do your testing.</p> <pre><code>if [ "$a" = test -o "$a" = Test ]; if test "$a" = test -o "$a" = Test; </code></pre> <p>If you need more power, then there's...</p> <h1><code>[[]]</code></h1> <p>This is a bash special. Not every shell needs to support this, and there's no binary fallback. It provides a more powerful comparison engine, notably <a href="http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching" rel="nofollow">pattern matching</a> and regular expression matching.</p> <pre><code>if [[ "$a" == [Tt]es? ]]; # pattern if [[ "$a" =~ ^[Tt]es.$ ]]; # RE </code></pre> <h1><code>(())</code></h1> <p>This is a bash special used for arithmetic expressions, and is true if the result of the calculation is non-zero. Not every shell needs to support this, and there's no binary fallback.</p> <pre><code>if (( x * (1 + x++) )); if let "x * (1 + x++)"; </code></pre> <p>Note that you can omit the <code>$</code> sign when referencing variables within <code>(( ... ))</code> or <code>let</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload