Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

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 Arno
All posts