title: Strange interaction of bash time, set -e and false, differences of bash 3 vs. bash 4
body: <p>Following recipe to <code>time</code> <code>false</code> under <code>set -e</code> succeeds (success in the sense that the <code>time</code> output can be seen):</p>
  
  <pre><code>(
  set +e
  time { ( set -e; false; echo no0; ); }
  echo yes0 $?
  )
  </code></pre>
  
  <p>But following recipes fail:</p>
  
  <pre><code>(
  set -e
  time false
  echo no1
  )
  </code></pre>
  
  <p>As well:</p>
  
  <pre><code>(
  set -e
  time { false; echo no2; }
  echo no2
  )
  </code></pre>
  
  <p>As well (surprisingly it outputs yes3 under bash3 and nothing under bash4):</p>
  
  <pre><code>(
  set -e
  time ( false; echo no3; )
  echo yes3 $?
  )
  </code></pre>
  
  <p>As well (not very suprising):</p>
  
  <pre><code>(
  set +e
  time { set -e; false; echo no4; }
  echo no4
  )
  </code></pre>
  
  <p>As well (surprise):</p>
  
  <pre><code>(
  set +e
  time ( set -e; false; echo no5; )
  echo yes5 $?
  )
  </code></pre>
  
  <p>And following succeeds under bash3 and does something completely different under bash4:</p>
  
  <pre><code>(
  set -e
  time { ( false; echo no7; ); echo yes6 $?; }
  echo yes6 $?
  )
  </code></pre>
  
  <p>Note that the "no" <code>echo</code>es are not printed, while the "yes" are output by bash3 (but not all by bash4).</p>
  
  <p>If you compare this with the subshell <code>(...)</code> processing under <code>set -e</code> it looks like the <code>time</code> builtin is executed with the subshell context in the <code>time (...)</code> case.  WTF?</p>
  
  <p>Tested with</p>
  
  <pre><code>GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
  Copyright (C) 2005 Free Software Foundation, Inc.
  </code></pre>
  
  <p>outputs</p>
  
  <pre><code>real    0m0.000s
  user    0m0.001s
  sys     0m0.000s
  yes0 1
  yes3 1
  yes5 1
  yes6 1
  
  real    0m0.000s
  user    0m0.000s
  sys     0m0.001s
  yes6 0
  </code></pre>
  
  <p>and</p>
  
  <pre><code>GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
  Copyright (C) 2009 Free Software Foundation, Inc.
  </code></pre>
  
  <p>outputs</p>
  
  <pre><code>real    0m0.001s
  user    0m0.000s
  sys     0m0.004s
  yes0 1
  yes5 1
  </code></pre>
  
  <p>Note that "yes3" and "yes6" cases show a huge difference in how bash3 and bash4 process <code>set -e</code>.</p>
  
  <p>But the "yes5" case is confusing.  It looks like "time" somehow is processed by the subshell and not in the outer shell.</p>
  
  <p><strong>Is this behavior enforced by POSIX, is one of the bashs buggy or is it just a <code>bash</code> special behavior?</strong></p>
  
  <p>Thanks ;)</p>
  
  <p>PS: If you are puzzled why this is not academic:  There once was a script running under <code>set -e</code> ("yes3" without <code>time</code>).  It was altered to log some timing information, the hack looks like "yes6".  But now bash4 comes around and it needes a fix again.</p>