title: expect_background affecting other expect's behavior
body: <p>I'm writting an expect script to automate some tests. To detect when a general error occurs (which can happen at any phase of the test), instead of repeating the same pattern (for instance, "Rebooting system") on each <code>expect</code> command, I decided to use <code>expect_background</code> for that kind of condition.</p>
  
  <p>What I understand about the <code>expect_background</code> command is that it is checked against all input text before the currently active <code>expect</code>. So, if both <code>expect_background</code> and <code>expect</code> are waiting for the same pattern, I expect (with the pun, please ;-) ) both actions to be triggered. For instance:</p>
  
  <pre><code>#!/usr/bin/expect -f
  
  spawn ./counter.sh
  
  expect_background {
    "5" { puts "expect-bg"; }
  }
  
  expect {
    "9" { puts "expect-9"; }
  }
  
  expect {
    "20" { puts "expect-20"; }
  }
  </code></pre>
  
  <p>The <code>./counter.sh</code> script counts from 1 to 20 with intervals of 1 second. According to the behavior I described above, <code>"expect-bg"</code> should be printed at <code>5</code> and <code>15</code>, <code>expect-9</code> at <code>9</code>, and <code>"expect-20"</code> at <code>20</code>. But here is what I get:</p>
  
  <pre><code>$ ./expect_bg.expect  
  spawn ./counter.sh
  1
  2
  3
  4
  5
  expect-bg
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  expect-bg
  16
  17
  18
  19
  20
  </code></pre>
  
  <p>Why is that happening? And how to I get the behavior described?</p>