title: How to make expect's expect command fail if the output isn't matched?
body: <p>Given the very simple script <code>script.expect</code></p>
  
  <pre><code>#!/usr/bin/expect
  
  spawn bash
  expect "#"
  send "/bin/false; echo \"process returned with $?\"\r"
  expect -exact "process returned with 0"
  send -- "exit\r"
  expect eof
  </code></pre>
  
  <p>I don't seem to be able how the script can not fail since <code>/bin/false</code> will cause the <code>echo</code> command to print <code>process returned with 1</code>, thus <code>process returned with 0</code> can never be matched on the <code>expect</code> command. I expect <code>expect script.expect</code> to fail with return code 1 after <code>expect -exact "process returned with 0"</code>.</p>
  
  <pre><code>#!/usr/bin/expect
  
  spawn bash
  expect "#"
  send "/bin/true; echo \"process returned with $?\"\r"
  expect -exact "process returned with 0" {
    send -- "exit\r"
    expect eof
    exit 0
  }
  exit 1
  </code></pre>
  
  <p>Even if I change the logic of my "application" in order to be able to test it with a positive/logically negated flow the outcome is still unexplainable.</p>
  
  <p>I worked through</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/10071636/how-to-make-expect-command-in-expect-program-script-to-wait-for-exact-string-mat">How to make expect command in expect program script to wait for exact string matching</a></li>
  <li><a href="https://www.thegeekstuff.com/2010/10/expect-examples" rel="nofollow noreferrer">https://www.thegeekstuff.com/2010/10/expect-examples</a></li>
  <li><a href="https://unix.stackexchange.com/questions/66520/error-handling-in-expect">https://unix.stackexchange.com/questions/66520/error-handling-in-expect</a></li>
  <li><a href="https://unix.stackexchange.com/questions/79310/expect-script-within-bash-exit-codes?rq=1">https://unix.stackexchange.com/questions/79310/expect-script-within-bash-exit-codes?rq=1</a></li>
  </ul>
  
  <p>and have no clue why <code>expect</code> is behaving this way.</p>