Install and Use 'expect' for Automated Bash Inputs

Installation Guide:

http://www.linuxfromscratch.org/blfs/view/svn/general/expect.html

https://stackoverflow.com/a/37638799/5581893

Use 'expect' to wait for prompts:

expect <<'HEREDOC'  
  spawn ./path/to/command;  

  expect {  
    "Some text to wait for 1" {  
      set timeout -1; 
      send "SOMEINPUT\\r"; 
      exp\_continue;  
    }  
"Some text to wait for 2" {  
      set timeout -1; 
      send "SOMEINPUT\\r"; 
      exp\_continue;  
    }  
    ...  
  }  
HEREDOC 

Note that 'expect' uses LF (\x0D) as Enter key.

Windows Enter = CRLF = \x0D\x0A = \r\n = MacEnter+NixEnter


You'll only receive email when they publish something new.

More from 19411
All posts