title: Bash: Compare exit codes of two functions
body: <p>Is there an elegant way to compare exit codes of two functions in bash? For example</p>
  
  <pre><code>b ()
  {
      local r=$(rand -M 2 -s $(( $(date +%s) + $1 )) );
      echo "b$1=$r";
      return $r;
  } # just random boolean    
  b1 () { b 1; return $?; } # some boolean function
  b2 () { b 2; return $?; } # another boolean function ( another seed )
  </code></pre>
  
  <p>I'd like to use something like this</p>
  
  <pre><code>if b1 == b2 ; then echo 'then'; else echo 'else'; fi
  </code></pre>
  
  <p>but stuck with this "not xor" implementation</p>
  
  <pre><code>if ! b1 &amp;&amp; ! b2 || ( b1 &amp;&amp; b2 ) ; then echo 'then'; else echo 'else'; fi
  </code></pre>
  
  <p>And speaking more generally, can one compare exit codes of two functions arithmetically and use that comparison in if statement?</p>