Server Fault is a question and answer site for system and network administrators. 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

I'm trying to learn how to use the expect command, to help me automate deployment of some software via shell scripts, and figured I start with something simple to get me started.

I've created a file in my home dir called 'foo' using:

touch foo

And I've created the following script saved as test.exp

spawn rm -i foo
expect "rm: remove regular empty file `foo'?"
send "y\r"

When I run the script using ./test.exp, it spawns the rm command, but it doesn't appear to send the Y and carriage return.

I know I don't have a typo in the expect string, as I've used copy and paste to put in the script.

What am I doing wrong?

share|improve this question
up vote 1 down vote accepted

Add this line after the send line:

expect eof
share|improve this answer
Thank you. Works perfectly. – Bryan May 8 '10 at 8:40

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.