title: Expect script return value
body: <p>I'm including simple Expect commands within a Bash script (I know I could be just writing a pure Expect script, but I would like to get it to work from within Bash).</p>
  
  <p>The script is below:</p>
  
  <pre><code>#!/bin/bash
  
  OUTPUT=$(expect -c '
  spawn ssh mihail911@blah.org
  expect "password:"
  send "dog\r"
  ')
  </code></pre>
  
  <p>Upon ssh'ing to the above address, it will return something of the form <code>mihail911's password:</code> on the prompt, so I think my expect line is valid.</p>
  
  <p>When I run this my script does not print anything. It does not even show the <code>password:</code> prompt. In general, even if I manually provide an incorrect password, I will receive a <code>Incorrect password</code>-type response prompt. Why is nothing printing and how can I get my script to execute properly?</p>
  
  <p>I have tried debugging by using the <code>-d</code> flag and it seems to show that at least the first expect prompt is being matched properly.</p>
  
  <p>In addition, what values should I expect in the <code>OUTPUT</code> variable? When I <code>echo</code> this variable, it simply prints the first the first command of the expect portion of the script and then <code>mihail911's password:</code>. Is this what it's supposed to be printing?</p>