title: Using expect interact, inside of a bash script, exits bash script prematurely
body: <p>When I use <strong><em>expect interact</em></strong> inside of a bash script to manually request the root password, it accepts the password, elevates to the root user, but exits without completing the rest of the bash script.</p>
  
  <p>I am migrating users from old CentOS machines to new RHEL machines. I have a process for doing this manually, but am attempting to automate the process. I have most of it working, but a couple of the steps require root level permissions. I am attempting to use expect interact from within the bash script to perform the <strong><em>su</em></strong> command to ensure the root password remains secure.</p>
  
  <pre><code>#!/bin/bash
  
  elevate()
  {
      echo 
      echo "You must be logged in as root to continue."
      echo "Press [Enter] to login as root."
      /usr/bin/expect -c 'expect "\n" { eval spawn su; interact }'
  }
  
  User=`whoami`
  if [ $User != "root" ]
  then
      elevate
  fi
  
  echo "script completed"
  
  exit
  </code></pre>
  
  <p>If I am logged in as root when I start the script, it never executes the elevate function and I get the "<em>script completed</em>" response. If I am logged in as any other user, the elevate function executes, I manually enter the root password, and the script exits without providing the "<em>script completed</em>" response, yet I am still logged in as the root user.</p>