title: Compound logical tests in bash
body: <p>A question about bash ....</p>
  
  <p>I wrote a little code to check whether a year is a leapyear.  The relevant part looks like:</p>
  
  <pre><code>if [ $testnum4 -eq 0 -a $testnum100 -ne 0 ] || [ $testnum400 -eq 0 ]
  then
    echo 0
  fi
  </code></pre>
  
  <p>Well, this code actually works.  My problem is that I'm still not quite sure what I was doing.  Just to see what would happen, I have tried several variations on this: enclosing the entire test expression in square backets, using <code>&amp;&amp;</code> where I have <code>-a</code> and <code>-o</code> where I have <code>||</code>, etc.  Nothing works except for the one expression that I wrote above.  I stumbled on it, and I'm glad I did, but the next time I have to do something like this, I would like to know what I am doing.</p>
  
  <p>So: Anyone have a quick explanation of how compound tests work in bash?  or a pointer to a good resource on this topic?</p>
  
  <p>Thanks.</p>
  
  <p>Here's a code that failed:</p>
  
  <pre><code>let testnum4=$1%4
  let testnum100=$1%100
  let testnum400=$1%400
  
  if [ $testnum4 -eq 0 &amp;&amp; $testnum100 -ne 0 ] -o [ $testnum400 -eq 0 ]
  then
    echo 0
  fi
  </code></pre>