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

So I have an expect script like this that works:

spawn scp* .
expect {
password: {send "mypassword"; exp_continue}

Based on the man page for expect, I think I should be able to do this instead from the command line to accomplish the same thing

expect -c "spawn scp* ." -c "expect {password: {send \"mypassword\\r\"; exp_continue}}"

But this returns to the terminal

spawn scp* .'s password: 

and then after a few seconds gives up without an error message and never does anything.


Yes, I'm well aware that I should not do this with scp and should instead use keys.

share|improve this question
up vote 0 down vote accepted

I'm not certain, but I suspect the multiple -c arguments are the problem. You can use a here-doc to pass the script on stdin:

expect <<'END'
spawn scp* .
expect {
password: {send "mypassword"; exp_continue}

The single quotes around the first 'END' will quote the whole document.

share|improve this answer
i did essentially this, but used echo to pipe into expect instead – G Gordon Worley III May 17 '13 at 14:05

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.