title: How to 'expect' something multiple times?
body: <p>I am using the following script to handle multiple user inputs with <code>expect</code>:</p>
  
  <pre><code>#!/usr/bin/bash
  
  TEST1="Test text"
  TEST2="Hello World"
  
  expect -c '
      spawn /home/alexander/read.sh
      expect -re "Please enter some input:.*"
      send "'"$TEST1"'\r\n"
      expect -re "Please enter other input:.*"
      send "'"$TEST2"'\r\n"
      '
  </code></pre>
  
  <p>Here is a different version: </p>
  
  <pre><code>#!/usr/bin/bash
  
  TEST1="Test text"
  TEST2="Hello World"
  
  expect -c '
      spawn /home/alexander/tasks/update/test/Expect/read.sh
      expect {
         "Please enter some input:" { send "'"$TEST1"'\r"  }
         exp_continue
      }
      expect {
          "Please enter other input:" { send "'"$TEST2"'\r" }
      }
      '
  </code></pre>
  
  <p>The <code>read.sh</code> script looks like follows: </p>
  
  <pre><code>#!/bin/bash
  
  read -p "Please enter some input: " input_variable
  echo "You entered: $input_variable"
  read -p "Please enter other input: " other_variable
  echo "You entered: $other_variable"
  </code></pre>
  
  <p>When I execute <code>read.sh</code> alone I am asked an input twice, which also is printed to stdout. The <code>expect</code> script, on the other hand, does not seem to handle the second input. The output I get is as follows: </p>
  
  <pre><code>spawn /home/alexander/read.sh
  Please enter some input: Test text
  
  You entered: Test text
  Please enter other input: 
  </code></pre>
  
  <p>What am I doing wrong, how to fix this?</p>
  
  <p>Remarks: </p>
  
  <ul>
  <li>The script needs to be a bash script with the bash-shebang. </li>
  <li>Adding <code>exp_continue</code> in the first script results in an <code>command returned bad code: -101</code> error.</li>
  </ul>