I'm using this expect script as an answerfile to a interactive shell script:


spawn ./interactivescriptname
expect "Question 1?"
send "something\r"
expect "Question 2?"
send "yes\r"
expect "Password?"
send "somepassword\r"

above works, but i want to use variables from a inputfile.

my variables files look like this:


Normally in bash i would use the source command, but this doesn't work in expect.

Any ideas?


One method would be to set TCL variables in a file (here, vars) and then source that file from the main script.

$ cat vars  
set var1 something
set var2 yes
set var3 Hunter2
$ cat script 
#!/usr/bin/env expect
source vars
puts $var3
$ chmod +x script
$ ./script 

It may be good to use more informative variable names than varN ...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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