Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using: CentOS 6.2 BASH shell

My script is something along the lines of

INSTALL_PATH="Enter install path"
/bin/su root -c "/usr/bin/expect << EOF
send $CR
EOF; ... do more stuff..."

Now sometimes my file asks "Would you like to uninstall?" how can I send this as an optional argument after the first send?

share|improve this question
also asked on stackoverflow -- – glenn jackman Apr 14 '12 at 10:49
up vote 2 down vote accepted

You can put multiple patterns inside an expect command

send \r
expect {
  {Would you like to uninstall?} {
    send yes\r

Take note that you send "\r" to "hit enter".

Also, the terminal word for a here-doc must appear by itself on a line -- it cannot be followed by "; more stuff"

share|improve this answer
Cool, will try this out and get back to you if it works as I'm shooting for. – Jason R. Mick Apr 17 '12 at 2:21
I received a "invalid command name "/usr/bin/expect"... it seems like the EOF (see above) is being skipped with the conditional expect is ignored. Do I need to keep a second EOF after your closing brace?? – Jason R. Mick Apr 21 '12 at 0:29
the lower case eof I have in my answer is for expect. The upper case EOF in your question is for the shell to terminate the here-doc – glenn jackman Apr 21 '12 at 12:32
Ah, so in other words I need both, right? (The EOF for the here-doc and the eof for the embedded expect script, correct?) I really appreciate the help! Going to test it out now... – Jason R. Mick Apr 21 '12 at 22:38
WOOO! Once I added that EOF back in everything worked like a charm. Your conditional expect, combined with the timeout proofing of Niall Byrne made the script work perfectly.... unintendended CUDA install is working perfectly. :) Here's Byrne's post:… – Jason R. Mick Apr 22 '12 at 19:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.